router

package
v0.0.0-...-dcedfe7 Latest Latest
Warning

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

Go to latest
Published: May 29, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	AccessTokenExpire int64  `mapstructure:"ACCESS_TOKEN_EXPIRE" default:"900"` // 15 min in secs
	PublicKeyFile     string `mapstructure:"PUBLIC_KEY_FILE" required:"true"`
	PrivateKeyFile    string `mapstructure:"PRIVATE_KEY_FILE" required:"true"`
}

AccessToken is the struct of env variables for access token

type Config

type Config struct {
	AccountAPIURL  string     `mapstructure:"ACCOUNT_API_URL" default:"/api/account"`
	Port           string     `mapstructure:"PORT" default:"8080"`
	MaxBodyBytes   int64      `mapstructure:"MAX_BODY_BYTES" default:"4194304"` // 4MB in Bytes ~ 4 * 1024 * 1024
	HandlerTimeout int64      `mapstructure:"HANDLER_TIMEOUT" default:"5"`
	DataSource     DataSource `mapstructure:"DATA_SOURCE,omitempty"`
	Token          Token      `mapstructure:"TOKEN,omitempty"`
}

Config is the struct works as template to parse env variables

func GetConfig

func GetConfig(path string, name string, fileType string) (*Config, error)

GetConfig parse configs file from local into defined Config struct - nested struct

type DataSource

type DataSource struct {
	PostGreSQL PostGreSQL `mapstructure:"POST_GRESQL,omitempty"`
	Redis      Redis      `mapstructure:"REDIS,omitempty"`
	GCP        GCP        `mapstructure:"GCP,omitempty"`
}

DataSource is the struct that contains env variables to connect data sources

type DataSources

type DataSources struct {
	PostgreSQLDB       *sqlx.DB
	RedisClient        *redis.Client
	CloudStorageClient *storage.Client
}

DataSources is the struct which contains variables representing data sources

func InitDS

func InitDS(config *Config) (*DataSources, error)

InitDS establishes connections to fields in DataSources

func (*DataSources) Close

func (d *DataSources) Close() error

Close to be used in graceful server shutdown

type GCP

type GCP struct {
	GCPImageBucket               string `mapstructure:"GCP_IMAGE_BUCKET" required:"true"`
	GoogleApplicationCredentials string `mapstructure:"GOOGLE_APPLICATION_CREDENTIALS" required:"true"`
	CloudConnectionTimeout       int64  `mapstructure:"CLOUD_CONNECTION_TIMEOUT" default:"5"`
}

GCP is the struct contains env variables which is needed to connect to Google Cloud Platform

type PostGreSQL

type PostGreSQL struct {
	PostGresHost              string `mapstructure:"POSTGRES_HOST" default:"postgres-account"`
	PostGresPort              string `mapstructure:"POSTGRES_PORT" default:"5432"`
	PostGresUser              string `mapstructure:"POSTGRES_USER" default:"postgres"`
	PostGresPassword          string `mapstructure:"POSTGRES_PASSWORD" required:"true"`
	PostGresDB                string `mapstructure:"POSTGRES_DB" default:"postgres"`
	PostGresSSL               string `mapstructure:"POSTGRES_SSL" default:"disable"`
	PostGresConnectionTimeOut int64  `mapstructure:"POSTGRES_CONNECTION_TIMEOUT" default:"10"`
}

PostGreSQL is the struct contains env variables which is needed to connect to PostGreSQL Client

type Redis

type Redis struct {
	RedisHost string `mapstructure:"REDIS_HOST" default:"redis-account"`
	RedisPort string `mapstructure:"REDIS_PORT" default:"6379"`
}

Redis is the struct contains env variables which is needed to connect to Redis Client

type RefreshToken

type RefreshToken struct {
	RefreshTokenExpire int64  `mapstructure:"REFRESH_TOKEN_EXPIRE" default:"259200"` // 3 days
	RefreshTokenSecret string `mapstructure:"REFRESH_TOKEN_SECRET" required:"true"`
}

RefreshToken is the struct of env variables for refresh token

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router is the struct used to init gin-gonic

func NewRouters

func NewRouters(config *Config, dataSources *DataSources) *Router

NewRouters is method to init router struct

func (*Router) InitGin

func (r *Router) InitGin() (*gin.Engine, error)

InitGin is a method which receive attributes of router and return *gin.Engine and error

type Token

type Token struct {
	AccessToken  AccessToken  `mapstructure:"ACCESS_TOKEN,omitempty"`
	RefreshToken RefreshToken `mapstructure:"REFRESH_TOKEN,omitempty"`
}

Token is the struct of env variables for token which contains access and refresh tokens

Jump to

Keyboard shortcuts

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