types

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package types defines universal types for configuration +genx:doc

Code generated by genx:doc DO NOT EDIT.

Index

Examples

Constants

View Source
const (
	TARGET_PROJECT     = "PROJECT"
	DEPLOY_ENVIRONMENT = "DEPLOY_ENVIRONMENT"
)
View Source
const MaskedPassword = "--------"

Variables

View Source
var ErrInvalidClosableValue = errors.New("invalid closable")
View Source
var ErrInvalidInitializerValue = errors.New("invalid initializer")

Functions

func CanBeInitialized added in v0.4.1

func CanBeInitialized(initializer any) bool

func Close added in v0.4.1

func Close(closable any) error

func CloseByContext added in v0.4.1

func CloseByContext(ctx context.Context, closable any) error

func Init added in v0.4.1

func Init(initializer any) error

func InitByContext added in v0.4.1

func InitByContext(ctx context.Context, initializer any) error

func IsClosable added in v0.4.1

func IsClosable(closable any) bool

func Span added in v0.4.0

func Span() func() time.Duration

Types

type CanShutdown added in v0.4.1

type CanShutdown interface {
	Shutdown(ctx context.Context) error
}

type Defaulter added in v0.4.1

type Defaulter interface {
	SetDefault()
}

type Duration added in v0.2.5

type Duration time.Duration

Duration extends time.Duraiton for

func (*Duration) DocOf added in v0.2.7

func (v *Duration) DocOf(names ...string) ([]string, bool)

func (Duration) IsZero added in v0.2.5

func (d Duration) IsZero() bool

func (Duration) MarshalText added in v0.2.5

func (d Duration) MarshalText() ([]byte, error)

func (Duration) String added in v0.2.5

func (d Duration) String() string

func (*Duration) UnmarshalText added in v0.2.5

func (d *Duration) UnmarshalText(data []byte) error

type Endpoint

type Endpoint[Option any] struct {
	// Address component connection endpoint address
	Address string
	// ExtraAddress for cluster multi-endpoint
	ExtraAddress []string
	// Auth support Endpoint auth info with username and password
	Auth Userinfo
	// Option component Option. if no option use EndpointNoOption
	Option Option
	// Cert X509KeyPair to support certification info
	Cert conftls.X509KeyPair
	// contains filtered or unexported fields
}

Endpoint a connectable endpoint Note options in url Param can override option

Example
grp := envx.NewGroup("TEST")
enc := envx.NewEncoder(grp)
err := enc.Encode(types.Endpoint[MockOption]{
	Address: "redis://localhost:6379/1",
	Auth:    types.Userinfo{Username: "username", Password: "LelzsnHN2xnJd/MB+JGIXWqd8pJPhPYfuRfDbrCsZE8="},
	Option:  MockOption{},
	Cert: conftls.X509KeyPair{
		Key: "key_path",
		Crt: "crt_path",
		CA:  "ca_path",
	},
})
if err != nil {
	return
}

// for configuration
fmt.Println(string(grp.Bytes()))
fmt.Println(string(grp.MaskBytes()))
Output:
TEST__Address=redis://localhost:6379/1
TEST__Auth_DecryptKeyEnv=
TEST__Auth_Password=LelzsnHN2xnJd/MB+JGIXWqd8pJPhPYfuRfDbrCsZE8=
TEST__Auth_Username=username
TEST__Cert_CA=ca_path
TEST__Cert_Crt=crt_path
TEST__Cert_Key=key_path
TEST__Option_Name=
TEST__Option_Timeout=0s

TEST__Address=redis://localhost:6379/1
TEST__Auth_DecryptKeyEnv=
TEST__Auth_Password=--------
TEST__Auth_Username=username
TEST__Cert_CA=ca_path
TEST__Cert_Crt=crt_path
TEST__Cert_Key=key_path
TEST__Option_Name=
TEST__Option_Timeout=0s

func (*Endpoint[Option]) AddOption added in v0.2.13

func (e *Endpoint[Option]) AddOption(k string, vs ...string)

func (*Endpoint[Option]) DocOf added in v0.2.7

func (v *Endpoint[Option]) DocOf(names ...string) ([]string, bool)

func (*Endpoint[Option]) Init added in v0.2.6

func (e *Endpoint[Option]) Init() (err error)

func (*Endpoint[Option]) IsZero

func (e *Endpoint[Option]) IsZero() bool

func (*Endpoint[Option]) Key

func (e *Endpoint[Option]) Key() string

Key returns Scheme, Host and Path. this method helps to identify a unique component

func (*Endpoint[Option]) LivenessCheck added in v0.2.6

func (e *Endpoint[Option]) LivenessCheck(ctx context.Context) (v liveness.Result)

func (*Endpoint[Option]) Scheme

func (e *Endpoint[Option]) Scheme() string

func (*Endpoint[Option]) SecurityString

func (e *Endpoint[Option]) SecurityString() string

SecurityString like String but auth info is hidden

func (*Endpoint[Option]) SetDefault added in v0.2.18

func (e *Endpoint[Option]) SetDefault()

func (*Endpoint[Option]) String

func (e *Endpoint[Option]) String() string

String returns full address info includes options and auth info

func (*Endpoint[Option]) URL added in v0.2.6

func (e *Endpoint[Option]) URL() url.URL

type EndpointNoOption added in v0.2.6

type EndpointNoOption = Endpoint[struct{}]

type Password

type Password string

Password as a string underlying and implements SecurityStringer

func (*Password) DocOf added in v0.2.7

func (v *Password) DocOf(names ...string) ([]string, bool)

func (Password) SecurityString

func (p Password) SecurityString() string

func (Password) String

func (p Password) String() string

type Runner added in v0.4.1

type Runner interface {
	Run(ctx context.Context) error
}

type Userinfo added in v0.2.6

type Userinfo struct {
	Username string
	Password Password

	// DecryptKeyEnv if not empty read key from env and decrypt password by AEC
	// with ECB mode and PKCS7 padding. default env key is PASSWORD_DEC_KEY
	DecryptKeyEnv string
}

Userinfo likes url.Userinfo but embed aes decryptor if DecryptKeyEnv is set. and implemented SecurityString to hide password

func (*Userinfo) DocOf added in v0.2.7

func (v *Userinfo) DocOf(names ...string) ([]string, bool)

func (*Userinfo) Init added in v0.2.6

func (u *Userinfo) Init() (err error)

func (*Userinfo) IsZero added in v0.2.6

func (u *Userinfo) IsZero() bool

func (Userinfo) SecurityString added in v0.2.6

func (u Userinfo) SecurityString() string

func (*Userinfo) SetDefault added in v0.2.6

func (u *Userinfo) SetDefault()

func (Userinfo) String added in v0.2.6

func (u Userinfo) String() string

func (Userinfo) Userinfo added in v0.2.6

func (u Userinfo) Userinfo() *url.Userinfo

Directories

Path Synopsis
Package mq provides a unified abstraction for message queue components.
Package mq provides a unified abstraction for message queue components.

Jump to

Keyboard shortcuts

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