-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (42 loc) · 1.23 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"flag"
"fmt"
"github.com/Arnobkumarsaha/oauth/handlers"
"net/http"
"os"
"strings"
)
var (
cl handlers.ClientDetails
authServer string
)
func init() {
cl.ID = os.Getenv("CLIENT_ID")
cl.Secret = os.Getenv("CLIENT_SECRET")
authServer = os.Getenv("AUTH_SERVER")
flag.StringVar(&cl.ID, "client-id", cl.ID, "client ID")
flag.StringVar(&cl.Secret, "client-secret", cl.Secret, "client Secret")
flag.StringVar(&authServer, "auth-server", authServer, "Available values : Github, Gitea")
flag.Parse()
fmt.Printf("==> %v, %v, %v \n", cl.ID, cl.Secret, authServer)
}
// go run *.go --client-id=<> --client-secret=<> --auth-server=github
func main() {
fs := http.FileServer(http.Dir("public"))
http.Handle("/", fs)
// determine which type to use
authServer = strings.ToUpper(authServer)
var g handlers.HandlerGetter
if authServer == "GITHUB" {
g = &handlers.Github{Client: cl}
} else if authServer == "GITEA" {
g = &handlers.Gitea{Client: cl}
} else if authServer == "B3" {
g = &handlers.B3{Client: cl}
}
http.HandleFunc("/oauth/redirect", handlers.GetRedirectHandler(g))
http.HandleFunc("/hello", handlers.GetHelloHandler(g))
fmt.Println("Listening to :8080")
_ = http.ListenAndServe(":8080", nil)
}