Skip to content

Commit

Permalink
adjust config using
Browse files Browse the repository at this point in the history
  • Loading branch information
ariebrainware committed Sep 21, 2020
1 parent 0f008df commit a0ac6ca
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 558 deletions.
14 changes: 7 additions & 7 deletions endpoint/paylist.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/ariebrainware/paylist-api/util"
)

var conf config.Config
// var config.Misc. config.Config

//User stuct for parse token
type User struct {
Expand All @@ -27,7 +27,7 @@ func FetchAllPaylist(c *gin.Context) {
tk := User{}
tokenString := c.Request.Header.Get("Authorization")
token, err := jwt.ParseWithClaims(tokenString, &tk, func(token *jwt.Token) (interface{}, error) {
return []byte(fmt.Sprint(conf.JWTSignature)), nil
return []byte(fmt.Sprint(config.Misc.JWTSignature)), nil
})
if err != nil || token == nil {
fmt.Println(err, token)
Expand All @@ -50,7 +50,7 @@ func FetchSinglePaylist(c *gin.Context) {
tk := User{}
tokenString := c.Request.Header.Get("Authorization")
token, err := jwt.ParseWithClaims(tokenString, &tk, func(token *jwt.Token) (interface{}, error) {
return []byte(fmt.Sprint(conf.JWTSignature)), nil
return []byte(fmt.Sprint(config.Misc.JWTSignature)), nil
})
if err != nil || token == nil {
fmt.Println(err, token)
Expand All @@ -74,7 +74,7 @@ func CreateUserPaylist(c *gin.Context) {
// Parse the payload from token
tokenString := c.GetHeader("Authorization")
token, err := jwt.ParseWithClaims(tokenString, &tk, func(token *jwt.Token) (interface{}, error) {
return []byte(fmt.Sprint(conf.JWTSignature)), nil
return []byte(fmt.Sprint(config.Misc.JWTSignature)), nil
})
if err != nil || token == nil {
fmt.Println(err, token)
Expand Down Expand Up @@ -116,7 +116,7 @@ func UpdateUserPaylist(c *gin.Context) {
// Parse the token payload
tokenString := c.GetHeader("Authorization")
token, err := jwt.ParseWithClaims(tokenString, &tk, func(token *jwt.Token) (interface{}, error) {
return []byte(fmt.Sprint(conf.JWTSignature)), nil
return []byte(fmt.Sprint(config.Misc.JWTSignature)), nil
})
if err != nil || token == nil {
fmt.Println(err, token)
Expand Down Expand Up @@ -170,7 +170,7 @@ func UpdateUserPaylistStatus(c *gin.Context) {
// Parse the token payload and validate the username is own the paylist
tokenString := c.GetHeader("Authorization")
token, err := jwt.ParseWithClaims(tokenString, &tk, func(token *jwt.Token) (interface{}, error) {
return []byte(fmt.Sprint(conf.JWTSignature)), nil
return []byte(fmt.Sprint(config.Misc.JWTSignature)), nil
})
if err != nil || token == nil {
fmt.Println(err, token)
Expand Down Expand Up @@ -214,7 +214,7 @@ func DeleteUserPaylist(c *gin.Context) {
// Parse the token payload and validate the username is own the paylist
tokenString := c.GetHeader("Authorization")
token, err := jwt.ParseWithClaims(tokenString, &tk, func(token *jwt.Token) (interface{}, error) {
return []byte(fmt.Sprint(conf.JWTSignature)), nil
return []byte(fmt.Sprint(config.Misc.JWTSignature)), nil
})
if err != nil || token == nil {
fmt.Println(err, token)
Expand Down
16 changes: 8 additions & 8 deletions endpoint/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func FetchAllUser(c *gin.Context) {
tk := User{}
tokenString := c.GetHeader("Authorization")
token, err := jwt.ParseWithClaims(tokenString, &tk, func(token *jwt.Token) (interface{}, error) {
return []byte(fmt.Sprint(conf.JWTSignature)), nil
return []byte(fmt.Sprint(config.Misc.JWTSignature)), nil
})
if err != nil || token == nil {
fmt.Println(err, token)
Expand Down Expand Up @@ -111,7 +111,7 @@ func UpdateUser(c *gin.Context) {
tk := User{}
tokenString := c.GetHeader("Authorization")
token, err := jwt.ParseWithClaims(tokenString, &tk, func(token *jwt.Token) (interface{}, error) {
return []byte(fmt.Sprint(conf.JWTSignature)), nil
return []byte(fmt.Sprint(config.Misc.JWTSignature)), nil
})
if err != nil || token == nil {
fmt.Println(err, token)
Expand Down Expand Up @@ -149,7 +149,7 @@ func EditPassword(c *gin.Context) {
tk := User{}
tokenString := c.GetHeader("Authorization")
token, err := jwt.ParseWithClaims(tokenString, &tk, func(token *jwt.Token) (interface{}, error) {
return []byte(fmt.Sprint(conf.JWTSignature)), nil
return []byte(fmt.Sprint(config.Misc.JWTSignature)), nil
})
if err != nil || token == nil {
fmt.Println(err, token)
Expand Down Expand Up @@ -193,7 +193,7 @@ func AddBalance(c *gin.Context) {
tk := User{}
tokenString := c.GetHeader("Authorization")
token, err := jwt.ParseWithClaims(tokenString, &tk, func(token *jwt.Token) (interface{}, error) {
return []byte(fmt.Sprintf(conf.JWTSignature)), nil
return []byte(fmt.Sprintf(config.Misc.JWTSignature)), nil
})
if err != nil || token == nil {
fmt.Println(err, token)
Expand Down Expand Up @@ -227,7 +227,7 @@ func DeleteUser(c *gin.Context) {
tk := User{}
tokenString := c.GetHeader("Authorization")
token, err := jwt.ParseWithClaims(tokenString, &tk, func(token *jwt.Token) (interface{}, error) {
return []byte(fmt.Sprintf(conf.JWTSignature)), nil
return []byte(fmt.Sprintf(config.Misc.JWTSignature)), nil
})
if err != nil || token == nil {
fmt.Println(err, token)
Expand Down Expand Up @@ -255,7 +255,7 @@ func FetchSingleUser(c *gin.Context) {
tk := User{}
tokenString := c.GetHeader("Authorization")
token, err := jwt.ParseWithClaims(tokenString, &tk, func(token *jwt.Token) (interface{}, error) {
return []byte(fmt.Sprintf(conf.JWTSignature)), nil
return []byte(fmt.Sprintf(config.Misc.JWTSignature)), nil
})
if err != nil || token == nil {
fmt.Println(err, token)
Expand Down Expand Up @@ -313,7 +313,7 @@ func Login(c *gin.Context) {
}
//Create JWT token
token := jwt.NewWithClaims(jwt.GetSigningMethod("HS256"), tk)
tokenString, err := token.SignedString([]byte(fmt.Sprintf(conf.JWTSignature)))
tokenString, err := token.SignedString([]byte(fmt.Sprintf(config.Misc.JWTSignature)))
if err != nil {
util.CallServerError(c, "error create token", err)
c.Abort()
Expand Down Expand Up @@ -351,7 +351,7 @@ func Auth(c *gin.Context) {
if jwt.GetSigningMethod("HS256") != token.Method {
return nil, fmt.Errorf("unexpected SigningMethod :%v", token.Header["alg"])
}
return []byte(fmt.Sprintf(conf.JWTSignature)), nil
return []byte(fmt.Sprintf(config.Misc.JWTSignature)), nil
})
config.DB.Model(&logging).Where("token = ? ", tokenString).Find(&logging)
if logging.Token == "" {
Expand Down
56 changes: 13 additions & 43 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,25 @@ module github.com/ariebrainware/paylist-api
go 1.12

require (
git.rushowl.sg/fossil/rush-logger v0.1.1 // indirect
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b // indirect
github.com/certifi/gocertifi v0.0.0-20200211180108-c7c1fbc02894 // indirect
github.com/cpuguy83/go-md2man v1.0.10 // indirect
github.com/cznic/b v0.0.0-20181122101859-a26611c4d92d // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/getsentry/raven-go v0.2.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gin-contrib/cors v1.3.1
github.com/gin-gonic/gin v1.5.0
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-redis/redis v6.15.9+incompatible // indirect
github.com/googleapis/gnostic v0.5.1 // indirect
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/hashicorp/go-hclog v0.14.1 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/jinzhu/gorm v1.9.12
github.com/leodido/go-urn v1.2.0 // indirect
github.com/lib/pq v1.3.0 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.3.0 // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/jinzhu/gorm v1.9.16
github.com/json-iterator/go v1.1.10 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/lib/pq v1.8.0 // indirect
github.com/mattn/go-sqlite3 v2.0.1+incompatible // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/prometheus/procfs v0.1.3 // indirect
github.com/ryanuber/columnize v2.1.2+incompatible // indirect
github.com/samuel/go-zookeeper v0.0.0-20200724154423-2164a8ac840e // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/streadway/amqp v1.0.0 // indirect
github.com/stripe/stripe-go v70.15.0+incompatible // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/tidwall/gjson v1.6.1 // indirect
github.com/stretchr/testify v1.5.1 // indirect
github.com/tkanos/gonfig v0.0.0-20181112185242-896f3d81fadf
github.com/willf/bitset v1.1.11 // indirect
go.mongodb.org/mongo-driver v1.4.1 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
google.golang.org/appengine v1.6.2 // indirect
github.com/ugorji/go v1.1.8 // indirect
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff // indirect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/go-playground/validator.v9 v9.31.0 // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.61.0 // indirect
k8s.io/api v0.19.2 // indirect
k8s.io/client-go v11.0.0+incompatible // indirect
k8s.io/klog v1.0.0 // indirect
k8s.io/utils v0.0.0-20200912215256-4140de9c8800 // indirect
modernc.org/b v1.0.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
Loading

0 comments on commit a0ac6ca

Please sign in to comment.