config

package
v0.0.0-...-d31700d Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

The parent config package get root dir when init, it panics if no root is found. So this package extract the common code, so it can be used by xiaomei.

Index

Examples

Constants

View Source
const EnvVar = "ProENV"

Variables

This section is empty.

Functions

func DetectReleaseConfigDirOf

func DetectReleaseConfigDirOf(majorEnv string) string

DetectReleaseConfigDirOf return the release config dir of a major environment, which contains clusters.yml, deploy.yml.

func DetectReleaseDir

func DetectReleaseDir() (dir string, hasDirectContent bool)

DetectReleaseDir return the top release dir of a project.

func GetDB

func GetDB(configMap strmap.StrMap, typ, key string) (interface{}, error)

func TimestampSign

func TimestampSign(ts int64, secret string) string
Example
fmt.Println(TimestampSign(123, "abc"))
Output:

21d9bfd0521686c89039b04bf66faf108c391e2334a371dfa51401c5e05a6e32

Types

type Config

type Config struct {
	Name           string        `yaml:"name"`
	RawExternalURL string        `yaml:"externalURL"`
	Secret         string        `yaml:"secret"`
	Cookie         Cookie        `yaml:"cookie"`
	Mailer         string        `yaml:"mailer"`
	Keepers        []string      `yaml:"keepers"`
	TimeZone       timeZone      `yaml:"timeZone"`
	Data           strmap.StrMap `yaml:"data"`

	Env          Environment    `yaml:"-"`
	ExternalURL  *url.URL       `yaml:"-"`
	TimeLocation *time.Location `yaml:"-"`
	// contains filtered or unexported fields
}

func Get

func Get(path, env string) *Config
Example
config := Get(`../release/img-app/config/test.yml`, `test`)
fmt.Println(GetDB(config.Data, `postgres`, `test`))

if v, err := GetDB(config.Data, `postgres`, `shards`); err != nil {
	fmt.Println(err)
} else if shards, ok := v.(*Shards); ok {
	for _, row := range shards.Shards {
		fmt.Printf("%+v\n", row)
	}
	fmt.Printf("%+v\n", shards.Settings)
} else {
	fmt.Println(v)
}
Output:

postgres://postgres:postgres@localhost/postgres?sslmode=disable <nil>
{No:1 Url:postgres://postgres:@localhost/test_1?sslmode=disable}
{No:2 Url:postgres://postgres:@localhost/test_2?sslmode=disable}
{IdSeqIncrementBy:1000}

func (*Config) DeployName

func (c *Config) DeployName() string

func (*Config) ExternalURLIsHTTPS

func (c *Config) ExternalURLIsHTTPS() bool

func (*Config) HttpCookie

func (c *Config) HttpCookie() http.Cookie

func (*Config) TimestampSign

func (c *Config) TimestampSign(ts int64) string
type Cookie struct {
	Name     string         `yaml:"name"`
	Domain   string         `yaml:"domain"`
	Path     string         `yaml:"path"`
	MaxAge   time2.Duration `yaml:"maxAge"`
	Secure   bool           `yaml:"secure"`
	HttpOnly bool           `yaml:"httpOnly"`
	SameSite string         `yaml:"sameSite"`
}

If use http.Cookie, it has no yaml tags, upper camel case is required, so define a new one.

type Environment

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

func NewEnv

func NewEnv(str string) Environment

str is of the form: [major-]minor

func (*Environment) IsCI

func (e *Environment) IsCI() bool

func (*Environment) IsDev

func (e *Environment) IsDev() bool

func (*Environment) IsPreview

func (e *Environment) IsPreview() bool

func (*Environment) IsProduction

func (e *Environment) IsProduction() bool

func (*Environment) IsQA

func (e *Environment) IsQA() bool

func (*Environment) IsTest

func (e *Environment) IsTest() bool

func (*Environment) Major

func (e *Environment) Major() string

func (*Environment) MajorIs

func (e *Environment) MajorIs(v string) bool

func (*Environment) Minor

func (e *Environment) Minor() string

func (*Environment) MinorIs

func (e *Environment) MinorIs(v string) bool

func (*Environment) PreviewToProduction

func (e *Environment) PreviewToProduction() Environment

PreviewToProduction return a production copy if IsPreview.

func (*Environment) String

func (e *Environment) String() string

func (*Environment) Vars

func (e *Environment) Vars() []string

type Shard

type Shard struct {
	No  int
	Url string
}

type Shards

type Shards struct {
	Shards   []Shard
	Settings ShardsSettings
}

func GetShards

func GetShards(m map[interface{}]interface{}, path string) (*Shards, error)

type ShardsSettings

type ShardsSettings struct {
	IdSeqIncrementBy int
}

func GetShardsSettings

func GetShardsSettings(v interface{}, path string) (*ShardsSettings, error)

Jump to

Keyboard shortcuts

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