types

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Examples

Constants

View Source
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, "", "    "))))

}

func Cost

func Cost() func() time.Duration

Types

type Duration added in v0.2.5

type Duration time.Duration

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 comparable] struct {
	// Address component connection endpoint address
	Address string
	Auth    Userinfo
	Option  Option
	Cert    conftls.X509KeyPair
	// contains filtered or unexported fields
}
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

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

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

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

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

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

func (e *Endpoint[Option]) LivenessCheck(ctx context.Context) LivenessData

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]) 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 LivenessChecker

type LivenessChecker interface {
	LivenessCheck(ctx context.Context) LivenessData
}

type LivenessData added in v0.2.6

type LivenessData struct {
	Reachable bool     `json:"reachable"`
	TTL       Duration `json:"ttl,omitempty"`
	Message   string   `json:"msg,omitempty"`
}

type Password

type Password string

func (Password) SecurityString

func (p Password) SecurityString() string

func (Password) String

func (p Password) String() string

type SchemedEndpoint added in v0.2.6

type SchemedEndpoint interface {
	Scheme() string
	Endpoint() string
}

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) 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

Jump to

Keyboard shortcuts

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