types

package
v0.2.22 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 11 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

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

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
	// 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]) 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]) IsZero

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

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

func (*LivenessData) DocOf added in v0.2.7

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

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

Jump to

Keyboard shortcuts

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