utils

package
v2.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2023 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClientIdNotFound = errors.New("ERROR: GITHUB OAUTH CLIENT ID NOT FOUND")
View Source
var ErrClientSecretNotFound = errors.New("ERROR: GITHUB OAUTH CLIENT SECRET NOT FOUND")
View Source
var ErrGithubAPIError = errors.New("ERROR: GITHUB API ERROR")
View Source
var ErrJwtSecretKeyNotFound = errors.New("ERROR: JWT SECRET KEY NOT FOUND")
View Source
var ErrJwtTokenInvalid = errors.New("ERROR: JWT TOKEN INVALID")

Functions

func DecodeJSONBody

func DecodeJSONBody(r *http.Request, data any) error

func GenerateLoginJwtString

func GenerateLoginJwtString(loginJwtFields LoginJwtFields) (string, error)

func GetDB

func GetDB() (db *gorm.DB, err error)

func GetOauthAccessToken

func GetOauthAccessToken(code string) (string, error)

func LogErr

func LogErr(r *http.Request, err error, errMsg string)

func LogErrAndRespond

func LogErrAndRespond(r *http.Request, w http.ResponseWriter, err error, errMsg string, statusCode int)

func LogInfo

func LogInfo(r *http.Request, info string)

func LogWarn

func LogWarn(r *http.Request, warning string)

func LogWarnAndRespond

func LogWarnAndRespond(r *http.Request, w http.ResponseWriter, warning string, statusCode int)

func MigrateModels

func MigrateModels(db *gorm.DB) error

Initial database model migration

func RespondWithHTTPMessage added in v2.0.1

func RespondWithHTTPMessage(r *http.Request, w http.ResponseWriter, status int, message string)

func RespondWithJson

func RespondWithJson(r *http.Request, w http.ResponseWriter, response any)

Types

type GHUserInfo

type GHUserInfo struct {
	Username string `json:"login"`
	Name     string `json:"name"`
	Email    string `json:"email"`
}

func GetOauthUserInfo

func GetOauthUserInfo(accessToken string) (*GHUserInfo, error)

type HTTPMessage added in v2.0.1

type HTTPMessage struct {
	// HTTP Response Status StatusCode
	StatusCode int    `json:"status_code"`
	Message    string `json:"message"`
}

type LoginJwtClaims

type LoginJwtClaims struct {
	LoginJwtFields
	jwt.RegisteredClaims
}

func ParseLoginJwtString

func ParseLoginJwtString(tokenString string) (*jwt.Token, *LoginJwtClaims, error)

type LoginJwtFields

type LoginJwtFields struct {
	Username string `json:"username"`
}

type OAuthAccessReqFields

type OAuthAccessReqFields struct {
	ClientId     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	Code         string `json:"code"`
}

Body fields for the request

type OAuthAccessResFields

type OAuthAccessResFields struct {
	AccessToken string `json:"access_token"`
	Error       string `json:"error"`
}

Body fields for the response

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL