config

package
v0.0.0-...-a170de9 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CF -> for use configs model
	CF = &Configs{}
)
View Source
var (
	RR = &ReturnResult{}
)

RR -> for use to return result model

Functions

func InitConfig

func InitConfig(configPath string, environment string) error

InitConfig init config

func InitReturnResult

func InitReturnResult(configPath string) error

InitReturnResult init return result

Types

type Configs

type Configs struct {
	UniversalTranslator *ut.UniversalTranslator
	Validator           *validator.Validate
	App                 struct {
		ProjectID  string `mapstructure:"project_name"`
		WebBaseURL string `mapstructure:"web_base_url"`
		APIBaseURL string `mapstructure:"api_base_url"`
		Version    string `mapstructure:"version"`
		Release    bool   `mapstructure:"release"`
		Port       int    `mapstructure:"port"`
	} `mapstructure:"app"`
	HTTPServer struct {
		ReadTimeout       time.Duration `mapstructure:"read_timeout"`
		WriteTimeout      time.Duration `mapstructure:"write_timeout"`
		ReadHeaderTimeout time.Duration `mapstructure:"read_header_timeout"`
	} `mapstructure:"http_server"`
	Postgresql struct {
		Host         string `mapstructure:"host"`
		Port         int    `mapstructure:"port"`
		Username     string `mapstructure:"username"`
		Password     string `mapstructure:"password"`
		DatabaseName string `mapstructure:"database_name"`
		DriverName   string `mapstructure:"driver_name"`
	} `mapstructure:"postgre_sql"`
	JWT struct {
		SecretKey  string `mapstructure:"secret_key"`
		ExpireTime struct {
			Day    time.Duration `mapstructure:"day"`
			Hour   time.Duration `mapstructure:"hour"`
			Minute time.Duration `mapstructure:"minute"`
		} `mapstructure:"expire_time"`
	} `mapstructure:"jwt"`
}

Configs models

type Environment

type Environment string

Environment environment

const (
	// LOCAL environment local
	LOCAL Environment = "local"
	// DEV environment develop
	DEV Environment = "dev"
	// PROD environment production
	PROD Environment = "prod"
)

type LocaleDescription

type LocaleDescription struct {
	EN     string `mapstructure:"en"`
	TH     string `mapstructure:"th"`
	Locale string `mapstructure:"success"`
}

LocaleDescription locale description

func (LocaleDescription) MarshalJSON

func (ld LocaleDescription) MarshalJSON() ([]byte, error)

MarshalJSON marshall json

func (*LocaleDescription) UnmarshalJSON

func (ld *LocaleDescription) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal json

type Result

type Result struct {
	Code        int               `json:"code" mapstructure:"code"`
	Description LocaleDescription `json:"message" mapstructure:"localization"`
}

Result result

func (Result) Error

func (rs Result) Error() string

Error error description

func (Result) ErrorCode

func (rs Result) ErrorCode() int

ErrorCode error code

func (Result) HTTPStatusCode

func (rs Result) HTTPStatusCode() int

HTTPStatusCode http status code

func (Result) WithLocale

func (rs Result) WithLocale(r *http.Request) Result

WithLocale with locale

type ReturnResult

type ReturnResult struct {
	InvalidRequest               Result `mapstructure:"invalid_request"`
	InvalidToken                 Result `mapstructure:"invalid_token"`
	JSONDuplicateOrInvalidFormat Result `mapstructure:"json_duplicate_or_invalid_format"`
	Internal                     struct {
		Success          Result `mapstructure:"success"`
		BadRequest       Result `mapstructure:"bad_request"`
		ConnectionError  Result `mapstructure:"connection_error"`
		DatabaseNotFound Result `mapstructure:"database_not_found"`
		Unauthorized     Result `mapstructure:"unauthorized"`
	} `mapstructure:"internal"`
}

ReturnResult return result model

func (*ReturnResult) CustomMessage

func (rr *ReturnResult) CustomMessage(messageEN, messageTH string) Result

CustomMessage custom message

func (*ReturnResult) GetLanguage

func (rr *ReturnResult) GetLanguage(r *http.Request) string

GetLanguage get language locale

type SwaggerInfoResult

type SwaggerInfoResult struct {
	Code        int    `json:"code"`
	Description string `json:"message"`
}

SwaggerInfoResult swagger info result

type SwaggerStatusResult

type SwaggerStatusResult struct {
	Status int `json:"status"`
}

Jump to

Keyboard shortcuts

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