config

package
v0.0.0-...-a28d39e Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AvailableStatusOnline  = "online"
	AvailableStatusOffline = "offline"
)
View Source
var (
	CF = &Configs{}
)
View Source
var (
	RR = &ReturnResult{}
)

RR -> for use to return result model

Functions

func InitConfig

func InitConfig() error

InitConfig init config

func InitReturnResult

func InitReturnResult() error

InitReturnResult init return result

Types

type AvailableConfig

type AvailableConfig struct {
	Status string `json:"status"`
}

type Configs

type Configs struct {
	UniversalTranslator *ut.UniversalTranslator
	Validator           *validator.Validate
	Path                string

	App struct {
		AvailableStatus string           // สถานะปิด/เปิดระบบ [on/off]
		ProjectId       string           `mapstructure:"PROJECT_ID"`
		ProjectName     string           `mapstructure:"PROJECT_NAME"`
		Version         string           `mapstructure:"VERSION"`
		WebBaseUrl      string           `mapstructure:"WEB_BASE_URL"`
		ApiBaseUrl      string           `mapstructure:"API_BASE_URL"`
		Port            int              `mapstructure:"PORT"`
		Environment     Environment      `mapstructure:"ENVIRONMENT"`
		Issuer          string           `mapstructure:"ISSUER"`
		Sources         []UserPassConfig `mapstructure:"SOURCES"`
	} `mapstructure:"APP"`

	HTTPServer struct {
		Prefork   bool `mapstructure:"PREFORK"`
		RateLimit struct {
			Max        int           `mapstructure:"MAX"`
			Expiration time.Duration `mapstructure:"EXPIRATION"`
			Enable     bool          `mapstructure:"ENABLE"`
		} `mapstructure:"RATELIMIT"`
	} `mapstructure:"HTTP_SERVER"`

	Web struct {
		DateFormat     string `mapstructure:"DATE_FORMAT"`
		DateTimeFormat string `mapstructure:"DATETIME_FORMAT"`
		TimeFormat     string `mapstructure:"TIME_FORMAT"`
	} `mapstructure:"WEB"`

	Swagger struct {
		Title       string `mapstructure:"TITLE"`
		Version     string `mapstructure:"VERSION"`
		Host        string `mapstructure:"HOST"`
		BaseURL     string `mapstructure:"BASE_URL"`
		Description string `mapstructure:"DESCRIPTION"`
		Enable      bool   `mapstructure:"ENABLE"`
	} `mapstructure:"SWAGGER"`

	JWT struct {
		AccessSecretKey   string        `mapstructure:"ACCESS_SECRET_KEY"`
		RefreshSecretKey  string        `mapstructure:"REFRESH_SECRET_KEY"`
		AccessExpireTime  time.Duration `mapstructure:"ACCESS_EXPIRE_TIME"`
		RefreshExpireTime time.Duration `mapstructure:"REFRESH_EXPIRE_TIME"`
	} `mapstructure:"JWT"`

	Database struct {
		RelaySQL DatabaseConfig `mapstructure:"RELAY_SQL"`
	} `mapstructure:"DATABASE"`

	HTMLTemplate struct {
		SystemMaintenance string `mapstructure:"SYSTEM_MAINTENANCE"`
	} `mapstructure:"HTML_TEMPLATE"`
}

func (*Configs) ReadConfigAvailableDescription

func (cf *Configs) ReadConfigAvailableDescription() (string, error)

ReadConfigAvailableDescription read config available description อ่าน config html ใช้แสดงเมื่อปิดระบบ

func (*Configs) SetConfigAvailableDescription

func (cf *Configs) SetConfigAvailableDescription(body string) error

SetConfigAvailableDescription set config available description สร้าง config html ใช้แสดงเมื่อปิดระบบ

func (*Configs) SetConfigAvailableStatus

func (cf *Configs) SetConfigAvailableStatus(status string) error

SetConfigAvailableStatus set config available status สร้าง config สถานะ ปิด/เปิด ระบบ

type DatabaseConfig

type DatabaseConfig 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"`
	Charset      string        `mapstructure:"CHARSET"`
	Timeout      string        `mapstructure:"TIMEOUT"`
	MaxIdleConns int           `mapstructure:"MAX_IDLE_CONNS"`
	MaxOpenConns int           `mapstructure:"MAX_OPEN_CONNS"`
	MaxLifetime  time.Duration `mapstructure:"MAX_LIFE_TIME"`
	Enable       bool          `mapstructure:"ENABLE"`
}

type Environment

type Environment string

Environment environment

const (
	Develop    Environment = "develop"
	Production Environment = "prod"
)

func (Environment) Production

func (e Environment) Production() bool

Production check is production

type Language

type Language string

Language language

const (
	// LanguageTH th
	LanguageTH Language = "th"
	// LanguageEN en
	LanguageEN Language = "en"
)

func (Language) IsValid

func (l Language) IsValid() bool

IsValid is valid

func (Language) String

func (l Language) String() string

String string

type LocaleDescription

type LocaleDescription struct {
	EN     string   `mapstructure:"en"`
	TH     string   `mapstructure:"th"`
	Locale Language `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(c fiber.Ctx) Result

WithLocale with locale

type ReturnResult

type ReturnResult struct {
	JSONDuplicateOrInvalidFormat Result `mapstructure:"json_duplicate_or_invalid_format"`
	InvalidToken                 Result `mapstructure:"invalid_token"`
	InvalidPermissionRole        Result `mapstructure:"invalid_permission_role"`
	TokenNotFound                Result `mapstructure:"token_not_found"`
	UserNotFound                 Result `mapstructure:"user_not_found"`
	EmployeeNotFound             Result `mapstructure:"employee_not_found"`

	Internal struct {
		Success          Result `mapstructure:"success"`
		General          Result `mapstructure:"general"`
		BadRequest       Result `mapstructure:"bad_request"`
		ConnectionError  Result `mapstructure:"connection_error"`
		DatabaseNotFound Result `mapstructure:"database_not_found"`
		Unauthorized     Result `mapstructure:"unauthorized"`
		Forbidden        Result `mapstructure:"forbidden"`
		TooManyRequests  Result `mapstructure:"too_many_requests"`
	} `mapstructure:"internal"`
}

ReturnResult return result model

func (*ReturnResult) CustomMessage

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

CustomMessage custom message

type SwaggerInfoResult

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

SwaggerInfoResult swagger info result

type UserPassConfig

type UserPassConfig struct {
	Username string `mapstructure:"USERNAME"`
	Password string `mapstructure:"PASSWORD"`
}

Jump to

Keyboard shortcuts

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