]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/blobdiff - api/api.go
Add column 'status' to market_configs.
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git] / api / api.go
index 7b7be49257a2949796b5435ccaddc6abd63893bf..79a13a5663fb5f2081458db268a0baefd7ed9731 100644 (file)
@@ -7,6 +7,22 @@ import (
        "github.com/gin-gonic/gin"
 )
 
+var CONFIG Config
+
+type Config struct {
+       JwtSecret           string `toml:"jwt_secret"`
+       PasswordResetSecret string `toml:"password_reset_secret"`
+       FreeSMSUser         string `toml:"free_sms_user"`
+       FreeSMSPass         string `toml:"free_sms_pass"`
+}
+
+func SetConfig(config Config) {
+       CONFIG = config
+
+       JWT_SECRET = []byte(config.JwtSecret)
+       PASSWORD_RESET_SECRET = []byte(config.PasswordResetSecret)
+}
+
 type Error struct {
        Code        ErrorCode
        UserMessage string
@@ -29,7 +45,22 @@ func (e Error) Error() string {
        return ""
 }
 
+func ErrorIs(err error, code ErrorCode) bool {
+       if err == nil {
+               return false
+       }
+
+       if apiError, ok := err.(*Error); !ok {
+               return false
+       } else {
+               return apiError.Code == code
+       }
+}
+
 func NewInternalError(err error) *Error {
+       if apiError, ok := err.(*Error); ok {
+               return apiError
+       }
        return &Error{InternalError, "internal error", err}
 }