mirror of
https://github.com/vx3r/wg-gen-web.git
synced 2024-11-22 02:31:57 +01:00
go fmt and golint
This commit is contained in:
parent
172551dcab
commit
6049ba8089
@ -5,6 +5,7 @@ import (
|
|||||||
"gitlab.127-0-0-1.fr/vx3r/wg-gen-web/api/v1"
|
"gitlab.127-0-0-1.fr/vx3r/wg-gen-web/api/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ApplyRoutes apply routes to gin engine
|
||||||
func ApplyRoutes(r *gin.Engine, private bool) {
|
func ApplyRoutes(r *gin.Engine, private bool) {
|
||||||
api := r.Group("/api")
|
api := r.Group("/api")
|
||||||
{
|
{
|
||||||
|
@ -16,8 +16,8 @@ import (
|
|||||||
func ApplyRoutes(r *gin.RouterGroup) {
|
func ApplyRoutes(r *gin.RouterGroup) {
|
||||||
g := r.Group("/auth")
|
g := r.Group("/auth")
|
||||||
{
|
{
|
||||||
g.GET("/oauth2_url", oauth2_url)
|
g.GET("/oauth2_url", oauth2URL)
|
||||||
g.POST("/oauth2_exchange", oauth2_exchange)
|
g.POST("/oauth2_exchange", oauth2Exchange)
|
||||||
g.GET("/user", user)
|
g.GET("/user", user)
|
||||||
g.GET("/logout", logout)
|
g.GET("/logout", logout)
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ func ApplyRoutes(r *gin.RouterGroup) {
|
|||||||
/*
|
/*
|
||||||
* generate redirect url to get OAuth2 code or let client know that OAuth2 is disabled
|
* generate redirect url to get OAuth2 code or let client know that OAuth2 is disabled
|
||||||
*/
|
*/
|
||||||
func oauth2_url(c *gin.Context) {
|
func oauth2URL(c *gin.Context) {
|
||||||
cacheDb := c.MustGet("cache").(*cache.Cache)
|
cacheDb := c.MustGet("cache").(*cache.Cache)
|
||||||
|
|
||||||
state, err := util.GenerateRandomString(32)
|
state, err := util.GenerateRandomString(32)
|
||||||
@ -62,7 +62,7 @@ func oauth2_url(c *gin.Context) {
|
|||||||
/*
|
/*
|
||||||
* exchange code and get user infos, if OAuth2 is disable just send fake data
|
* exchange code and get user infos, if OAuth2 is disable just send fake data
|
||||||
*/
|
*/
|
||||||
func oauth2_exchange(c *gin.Context) {
|
func oauth2Exchange(c *gin.Context) {
|
||||||
var loginVals model.Auth
|
var loginVals model.Auth
|
||||||
if err := c.ShouldBind(&loginVals); err != nil {
|
if err := c.ShouldBind(&loginVals); err != nil {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"gitlab.127-0-0-1.fr/vx3r/wg-gen-web/api/v1/server"
|
"gitlab.127-0-0-1.fr/vx3r/wg-gen-web/api/v1/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ApplyRoutes apply routes to gin router
|
||||||
func ApplyRoutes(r *gin.RouterGroup, private bool) {
|
func ApplyRoutes(r *gin.RouterGroup, private bool) {
|
||||||
v1 := r.Group("/v1.0")
|
v1 := r.Group("/v1.0")
|
||||||
{
|
{
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Auth interface to implement as auth provider
|
||||||
type Auth interface {
|
type Auth interface {
|
||||||
Setup() error
|
Setup() error
|
||||||
CodeUrl(state string) string
|
CodeUrl(state string) string
|
||||||
@ -18,6 +19,7 @@ type Auth interface {
|
|||||||
UserInfo(oauth2Token *oauth2.Token) (*model.User, error)
|
UserInfo(oauth2Token *oauth2.Token) (*model.User, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAuthProvider get an instance of auth provider based on config
|
||||||
func GetAuthProvider() (Auth, error) {
|
func GetAuthProvider() (Auth, error) {
|
||||||
var oauth2Client Auth
|
var oauth2Client Auth
|
||||||
var err error
|
var err error
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Fake in order to implement interface, struct is required
|
||||||
type Fake struct{}
|
type Fake struct{}
|
||||||
|
|
||||||
// Setup validate provider
|
// Setup validate provider
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Github in order to implement interface, struct is required
|
||||||
type Github struct{}
|
type Github struct{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Oauth2idc in order to implement interface, struct is required
|
||||||
type Oauth2idc struct{}
|
type Oauth2idc struct{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
|
// Auth structure
|
||||||
type Auth struct {
|
type Auth struct {
|
||||||
Oauth2 bool `json:"oauth2"`
|
Oauth2 bool `json:"oauth2"`
|
||||||
ClientId string `json:"clientId"`
|
ClientId string `json:"clientId"`
|
||||||
|
@ -2,6 +2,7 @@ package model
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
|
// User structure
|
||||||
type User struct {
|
type User struct {
|
||||||
Sub string `json:"sub"`
|
Sub string `json:"sub"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// AuthTokenHeaderName http header for token transport
|
||||||
AuthTokenHeaderName = "x-wg-gen-web-auth"
|
AuthTokenHeaderName = "x-wg-gen-web-auth"
|
||||||
// RegexpEmail check valid email
|
// RegexpEmail check valid email
|
||||||
RegexpEmail = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
|
RegexpEmail = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
|
||||||
|
Loading…
Reference in New Issue
Block a user