Documentation
¶
Overview ¶
Package types defines universal types for configuration +genx:doc
Code generated by genx:doc DO NOT EDIT.
Index ¶
- Constants
- func CheckLiveness(ctx context.Context, endpoints ...SchemedEndpoint) map[string]map[string]LivenessData
- func Cost() func() time.Duration
- type Duration
- type Endpoint
- func (e *Endpoint[Option]) AddOption(k string, vs ...string)
- func (v *Endpoint[Option]) DocOf(names ...string) ([]string, bool)
- func (e *Endpoint[Option]) Endpoint() string
- func (e *Endpoint[Option]) Init() (err error)
- func (e *Endpoint[Option]) IsZero() bool
- func (e *Endpoint[Option]) LivenessCheck(ctx context.Context) LivenessData
- func (e *Endpoint[Option]) Scheme() string
- func (e *Endpoint[Option]) SecurityString() string
- func (e *Endpoint[Option]) SetDefault()
- func (e *Endpoint[Option]) String() string
- func (e *Endpoint[Option]) URL() url.URL
- type EndpointNoOption
- type LivenessChecker
- type LivenessData
- type Password
- type SchemedEndpoint
- type Userinfo
Examples ¶
Constants ¶
const ( TARGET_PROJECT = "PROJECT" DEPLOY_ENVIRONMENT = "DEPLOY_ENVIRONMENT" )
const MaskedPassword = "--------"
Variables ¶
This section is empty.
Functions ¶
func CheckLiveness ¶ added in v0.2.6
func CheckLiveness(ctx context.Context, endpoints ...SchemedEndpoint) map[string]map[string]LivenessData
Example ¶
package main
import (
"context"
"encoding/json"
"log"
"github.com/xoctopus/x/misc/must"
"github.com/xoctopus/confx/pkg/types"
)
func main() {
endpoints := []types.SchemedEndpoint{
&types.EndpointNoOption{Address: "redis://localhost:6379/1"},
&types.EndpointNoOption{Address: "https://www.google.com:443"},
&types.EndpointNoOption{Address: "http://www.google.com"},
}
for _, ep := range endpoints {
if x, ok := ep.(interface{ Init() error }); ok {
if err := x.Init(); err != nil {
return
}
}
}
m := types.CheckLiveness(context.Background(), endpoints...)
log.Println("\n" + string(must.NoErrorV(json.MarshalIndent(m, "", " "))))
}
Types ¶
type Duration ¶ added in v0.2.5
Duration extends time.Duraiton for
func (Duration) MarshalText ¶ added in v0.2.5
func (*Duration) UnmarshalText ¶ added in v0.2.5
type Endpoint ¶
type Endpoint[Option any] struct { // Address component connection endpoint address Address 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]) Endpoint ¶ added in v0.2.6
Endpoint 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) LivenessData
func (*Endpoint[Option]) SecurityString ¶
SecurityString like String but auth info is hidden
func (*Endpoint[Option]) SetDefault ¶ added in v0.2.18
func (e *Endpoint[Option]) SetDefault()
type EndpointNoOption ¶ added in v0.2.6
type EndpointNoOption = Endpoint[struct{}]
type LivenessChecker ¶
type LivenessChecker interface {
LivenessCheck(ctx context.Context) LivenessData
}
LivenessChecker check remote endpoint liveness Endpoint already implements it, components should override that
type LivenessData ¶ added in v0.2.6
type LivenessData struct {
// Reachable if remote endpoint is reachable
Reachable bool `json:"reachable"`
// RTT probes round trip time to remote endpoint
RTT Duration `json:"rtt,omitempty"`
// Message result or extended message
Message string `json:"msg,omitempty"`
}
LivenessData presents LivenessChecker result
type Password ¶
type Password string
Password as a string underlying and implements SecurityStringer
func (Password) SecurityString ¶
type SchemedEndpoint ¶ added in v0.2.6
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) SecurityString ¶ added in v0.2.6
func (*Userinfo) SetDefault ¶ added in v0.2.6
func (u *Userinfo) SetDefault()