core

package module
v0.0.0-...-9f00c22 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

README

go-core

1. Environment Parser

You can now simple create env.yaml file with profile names (default, dev, local, etc.)

default:
    URL: http://test.com
    PORT: 80

dev:
    PORT: 8080

    #database
    DB_HOST: <url>
    DB_PORT: 1234
    DB_NAME: dbname
    DB_USER: dbuser
    DB_PASS: dbpass

And you can simple load env variables by:
core.LoadEnv(profiles...), example core.LoadEnv("dev")
Please note that default profile will be loaded automatically, no need to specify in LoadEnv as a parameter.

By default method will try to load file with name env.yaml. If your file name is different then use method
core.LoadEnvFile(filename, profiles...)

Limitations

Currently we support only one level of depth

profilename:           # 1st level is profilename
    URL: <url>         # 2nd level is env key:value property
    DATABASE:  
        URL: <url>     # 3rd level not allowed

2. Log Helpers

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Conn *pg.DB

Functions

func ConnectDb

func ConnectDb(c *DbConf) *pg.DB

func HealthHandler

func HealthHandler(w http.ResponseWriter, r *http.Request)

func LoadEnv

func LoadEnv(profiles ...string)

func LoadEnvFile

func LoadEnvFile(filename string, profiles ...string)

func LogrusFormatter

func LogrusFormatter(f *runtime.Frame) (string, string)

func LogrusJsonFmt

func LogrusJsonFmt() *logrus.JSONFormatter

func LogrusTextFmt

func LogrusTextFmt() *logrus.TextFormatter

func MapHeaders

func MapHeaders(r *http.Request, keys ...string) map[string]string

func OK

func OK(w http.ResponseWriter, body interface{})

func ParseRequestBody

func ParseRequestBody(req *http.Request, model interface{}) error

func ParseResponseBody

func ParseResponseBody(req *http.Response, model interface{}) error

Types

type DbConf

type DbConf struct {
	Host          string
	Port          string
	Name          string
	User          string
	Password      string
	HasMigrations bool
	MigrationPath string
	Insecure      bool
	MaxRetries    int
	MaxConnAge    time.Duration
}

Jump to

Keyboard shortcuts

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