Passed
Push — main ( 3ec306...c5cfaa )
by Yume
01:53 queued 44s
created

pkg/oauth/shared.go   A

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 35
dl 0
loc 69
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A oauth.GetCallbackURL 0 2 1
A oauth.InitDiscord 0 2 1
A oauth.GetDiscordURL 0 2 1
A oauth.GetFrontendURL 0 2 1
A oauth.GetGithubClientID 0 2 1
A oauth.SetJSONHelper 0 2 1
A oauth.SetOauthConfig 0 2 1
A oauth.InitGithub 0 2 1
1
package oauth
2
3
import (
4
	"github.com/memnix/memnix-rest/pkg/json"
5
)
6
7
const (
8
	// RequestFailed is the error message when a request fails.
9
	RequestFailed = "request failed"
10
	// ResponseFailed is the error message when a response fails.
11
	ResponseFailed = "response failed"
12
)
13
14
var jsonHelper = json.NewJSON(&json.NativeJSON{})
15
16
type GlobalConfig struct {
17
	CallbackURL string
18
	FrontendURL string
19
}
20
21
var (
22
	githubConfig  GithubConfig
23
	discordConfig DiscordConfig
24
	oauthConfig   GlobalConfig
25
)
26
27
type GithubConfig struct {
28
	ClientID     string
29
	ClientSecret string
30
}
31
32
type DiscordConfig struct {
33
	ClientID     string
34
	ClientSecret string
35
	URL          string
36
}
37
38
func GetGithubClientID() string {
39
	return githubConfig.ClientID
40
}
41
42
func GetCallbackURL() string {
43
	return oauthConfig.CallbackURL
44
}
45
46
func GetFrontendURL() string {
47
	return oauthConfig.FrontendURL
48
}
49
50
func GetDiscordURL() string {
51
	return discordConfig.URL
52
}
53
54
func SetJSONHelper(helper json.Helper) {
55
	jsonHelper = json.NewJSON(helper)
56
}
57
58
// InitGithub initializes the Github oauth configuration.
59
func InitGithub(config GithubConfig) {
60
	githubConfig = config
61
}
62
63
// InitDiscord initializes the Discord oauth configuration.
64
func InitDiscord(config DiscordConfig) {
65
	discordConfig = config
66
}
67
68
func SetOauthConfig(config GlobalConfig) {
69
	oauthConfig = config
70
}
71