domain/oauth.go   A
last analyzed

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 35
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A domain.*GithubLogin.ToUser 0 9 1
A domain.*DiscordLogin.ToUser 0 9 1
1
package domain
2
3
import (
4
	"strconv"
5
)
6
7
// GithubLogin is a struct that represents the Github login response.
8
type GithubLogin struct {
9
	Login      string `json:"login"`
10
	NodeID     string `json:"node_id"`
11
	AvatarURL  string `json:"avatar_url"`
12
	GravatarID string `json:"gravatar_id"`
13
	URL        string `json:"url"`
14
	Bio        string `json:"bio"`
15
	Email      string `json:"email"`
16
	ID         int    `json:"id"`
17
}
18
19
// ToUser converts the GithubLogin to a User.
20
func (g *GithubLogin) ToUser() User {
21
	return User{
22
		Username:      g.Login,
23
		Email:         g.Email,
24
		Permission:    PermissionUser,
25
		Avatar:        g.AvatarURL,
26
		Oauth:         true,
27
		OauthProvider: "github",
28
		OauthID:       strconv.Itoa(g.ID),
29
	}
30
}
31
32
// DiscordLogin is a struct that represents the Discord login response.
33
type DiscordLogin struct {
34
	ID       string `json:"id"`
35
	Username string `json:"username"`
36
	Avatar   string `json:"avatar"`
37
	Email    string `json:"email"`
38
}
39
40
// ToUser converts the DiscordLogin to a User.
41
func (d *DiscordLogin) ToUser() User {
42
	return User{
43
		Username:      d.Username,
44
		Email:         d.Email,
45
		Permission:    PermissionUser,
46
		Avatar:        "https://cdn.discordapp.com/avatars/" + d.ID + "/" + d.Avatar + ".png",
47
		Oauth:         true,
48
		OauthProvider: "discord",
49
		OauthID:       d.ID,
50
	}
51
}
52