Documentation ¶
Index ¶
- Variables
- func ClientWithTLS(tlsCfg *tls.Config) *http.Client
- func GetCPUPercentage() float64
- func GetJSON(client *http.Client, url string, v interface{}) error
- func GetRawInfo(app string) string
- func OriginError(err error) error
- func ParseHostPortAddr(s string) ([]string, error)
- func PrintInfo(app string)
- func SliceToMap(slice []string) map[string]interface{}
- func StringsToInterfaces(strs []string) []interface{}
- func TSOToRoughTime(ts int64) time.Time
- func ToTLSConfig(caPath, certPath, keyPath string) (*tls.Config, error)
- func ToTLSConfigWithVerify(caPath, certPath, keyPath string, verifyCN []string) (*tls.Config, error)
- func ToTLSConfigWithVerifyByRawbytes(caData, certData, keyData []byte, verifyCN []string) (*tls.Config, error)
- type TLS
Constants ¶
This section is empty.
Variables ¶
var ( Version = "None" BuildTS = "None" GitHash = "None" GitBranch = "None" )
Version information.
Functions ¶
func ClientWithTLS ¶
ClientWithTLS creates a http client wit tls
func GetCPUPercentage ¶
func GetCPUPercentage() float64
GetCPUPercentage calculates CPU usage and returns percentage in float64(e.g. 2.5 means 2.5%). http://man7.org/linux/man-pages/man2/getrusage.2.html
func GetJSON ¶
GetJSON fetches a page and parses it as JSON. The parsed result will be stored into the `v`. The variable `v` must be a pointer to a type that can be unmarshalled from JSON.
Example:
client := &http.Client{} var resp struct { IP string } if err := util.GetJSON(client, "http://api.ipify.org/?format=json", &resp); err != nil { return errors.Trace(err) } fmt.Println(resp.IP)
func ParseHostPortAddr ¶
ParseHostPortAddr returns a scheme://host:port or host:port list
func SliceToMap ¶
SliceToMap converts slice to map
func StringsToInterfaces ¶
func StringsToInterfaces(strs []string) []interface{}
StringsToInterfaces converts string slice to interface slice
func TSOToRoughTime ¶
TSOToRoughTime translates tso to rough time that used to display
func ToTLSConfig ¶
ToTLSConfig generates tls's config.
Types ¶
type TLS ¶
type TLS struct {
// contains filtered or unexported fields
}
TLS saves some information about tls
func NewTLS ¶
NewTLS constructs a new HTTP client with TLS configured with the CA, certificate and key paths.
If the CA path is empty, returns an instance where TLS is disabled.
func NewTLSFromMockServer ¶
NewTLSFromMockServer constructs a new TLS instance from the certificates of an *httptest.Server.
func (*TLS) ToGRPCDialOption ¶
func (tc *TLS) ToGRPCDialOption() grpc.DialOption
ToGRPCDialOption constructs a gRPC dial option.
func (*TLS) ToGRPCServerOption ¶
func (tc *TLS) ToGRPCServerOption() grpc.ServerOption
ToGRPCServerOption constructs a gRPC server option.