-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.go
112 lines (96 loc) · 3.32 KB
/
server.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"fmt"
"net/http"
"os"
"strconv"
jv "github.com/Ulbora/GoAuth2JwtValidator"
udb "github.com/Ulbora/GoAuth2Users/db"
han "github.com/Ulbora/GoAuth2Users/handlers"
m "github.com/Ulbora/GoAuth2Users/managers"
lg "github.com/Ulbora/Level_Logger"
db "github.com/Ulbora/dbinterface"
mdb "github.com/Ulbora/dbinterface_mysql"
"github.com/gorilla/mux"
)
//GO111MODULE=on go mod init github.com/Ulbora/GoAuth2Users
func main() {
var dbi db.Database
var mydb mdb.MyDB
var goAuth2UsersHost string
var goAuth2UsersDbUser string
var goAuth2UsersDbPassword string
var goAuth2UsersDatabase string
if os.Getenv("GO_AUTH2_USERS_HOST") != "" {
goAuth2UsersHost = os.Getenv("GO_AUTH2_USERS_HOST")
} else {
goAuth2UsersHost = "localhost:3306"
}
if os.Getenv("GO_AUTH2_USERS_DB_USER") != "" {
goAuth2UsersDbUser = os.Getenv("GO_AUTH2_USERS_DB_USER")
} else {
goAuth2UsersDbUser = "admin"
}
if os.Getenv("GO_AUTH2_USERS_DB_PASSWORD") != "" {
goAuth2UsersDbPassword = os.Getenv("GO_AUTH2_USERS_DB_PASSWORD")
} else {
goAuth2UsersDbPassword = "admin"
}
if os.Getenv("GO_AUTH2_USERS_DATABASE") != "" {
goAuth2UsersDatabase = os.Getenv("GO_AUTH2_USERS_DATABASE")
} else {
goAuth2UsersDatabase = "go_auth2_users"
}
mydb.Host = goAuth2UsersHost
mydb.User = goAuth2UsersDbUser
mydb.Password = goAuth2UsersDbPassword
mydb.Database = goAuth2UsersDatabase
dbi = &mydb
dbi.Connect()
var userDB udb.UserDB
userDB.DB = dbi
var l lg.Logger
l.LogLevel = lg.AllLevel
var uman m.UserManager
uman.UserDB = &userDB
uman.Log = &l
var uh han.UserHandler
uh.Log = &l
uh.Manager = &uman
var mc jv.OauthClient
//var proxy gp.GoProxy
//mc.Proxy = &proxy
//var compress cp.JwtCompress
//mc.JwtCompress = compress
uh.ValidatorClient = mc.GetNewClient()
h := uh.GetNew()
router := mux.NewRouter()
port := "3001"
envPort := os.Getenv("PORT")
if envPort != "" {
portInt, _ := strconv.Atoi(envPort)
if portInt != 0 {
port = envPort
}
}
router.HandleFunc("/rs/role/add", h.AddRole).Methods("POST")
router.HandleFunc("/rs/role/get/{id}", h.GetRole).Methods("GET")
router.HandleFunc("/rs/role/list", h.GetRoleList).Methods("GET")
router.HandleFunc("/rs/role/delete/{id}", h.DeleteRole).Methods("DELETE")
router.HandleFunc("/rs/user/add", h.AddUser).Methods("POST")
router.HandleFunc("/rs/user/update", h.UpdateUser).Methods("PUT")
router.HandleFunc("/rs/user/get/{username}/{clientId}", h.GetUser).Methods("GET")
router.HandleFunc("/rs/user/list", h.GetUserList).Methods("GET")
router.HandleFunc("/rs/user/search/{clientId}", h.SearchUserList).Methods("GET")
router.HandleFunc("/rs/user/delete/{username}/{clientId}", h.DeleteUser).Methods("DELETE")
router.HandleFunc("/rs/client/user/add", h.ClientAddUser).Methods("POST")
router.HandleFunc("/rs/client/user/update", h.ClientUpdateUser).Methods("PUT")
router.HandleFunc("/rs/client/user/get/{username}", h.ClientGetUser).Methods("GET")
router.HandleFunc("/rs/client/user/search", h.ClientSearchUserList).Methods("GET")
router.HandleFunc("/rs/client/user/delete/{username}", h.ClientDeleteUser).Methods("DELETE")
router.HandleFunc("/rs/user/login", h.LoginUser).Methods("POST")
router.HandleFunc("/rs/loglevel", h.SetLogLevel).Methods("POST")
l.LogLevel = lg.OffLevel
fmt.Println("Starting server Oauth2 Server on " + port)
http.ListenAndServe(":"+port, router)
}