base

package
v0.1.46 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigPath = ".ucloud"

ConfigPath 配置文件路径

View Source
const DateTimeLayout = "2006-01-02/15:04:05"

DateTimeLayout 时间格式

View Source
const DefaultBaseURL = "https://api.ucloud.cn/"

DefaultBaseURL location of api server

View Source
const DefaultDasURL = "https://das-rpt.ucloud.cn/log"
View Source
const DefaultMaxRetryTimes = 3

DefaultMaxRetryTimes default timeout for requesting api, 15s

View Source
const DefaultProfile = "default"

DefaultProfile name of default profile

View Source
const DefaultTimeoutSec = 15

DefaultTimeoutSec default timeout for requesting api, 15s

View Source
const GAP = 2

GAP 表格列直接的间隔字符数

View Source
const LocalFileMode os.FileMode = 0600

LocalFileMode file mode of $HOME/ucloud/*

View Source
const Version = "0.1.46"

Version 版本号

Variables

View Source
var AggConfigListIns = &AggConfigManager{}

AggConfigListIns 配置列表, 进程启动时从本地文件加载

View Source
var ClientConfig *sdk.Config

ClientConfig 创建sdk client参数

View Source
var ConfigFilePath = fmt.Sprintf("%s/%s", GetConfigDir(), "config.json")

ConfigFilePath path of config.json

View Source
var ConfigIns = &AggConfig{
	Profile:       DefaultProfile,
	BaseURL:       DefaultBaseURL,
	Timeout:       DefaultTimeoutSec,
	MaxRetryTimes: sdk.Int(DefaultMaxRetryTimes),
}

ConfigIns 配置实例, 程序加载时生成

View Source
var CredentialFilePath = fmt.Sprintf("%s/%s", GetConfigDir(), "credential.json")

CredentialFilePath path of credential.json

View Source
var CredentialFilePathInCloudShell = os.Getenv("CLOUD_SHELL_CREDENTIAL_FILE")

Cxt 上下文

View Source
var InCloudShell = os.Getenv("CLOUD_SHELL") == "true"
View Source
var RegionLabel = map[string]string{
	"cn-bj1":       "Beijing1",
	"cn-bj2":       "Beijing2",
	"cn-sh2":       "Shanghai2",
	"cn-gd":        "Guangzhou",
	"cn-qz":        "Quanzhou",
	"hk":           "Hongkong",
	"us-ca":        "LosAngeles",
	"us-ws":        "Washington",
	"ge-fra":       "Frankfurt",
	"th-bkk":       "Bangkok",
	"kr-seoul":     "Seoul",
	"sg":           "Singapore",
	"tw-kh":        "Kaohsiung",
	"rus-mosc":     "Moscow",
	"jpn-tky":      "Tokyo",
	"tw-tp":        "TaiPei",
	"uae-dubai":    "Dubai",
	"idn-jakarta":  "Jakarta",
	"ind-mumbai":   "Bombay",
	"bra-saopaulo": "SaoPaulo",
	"uk-london":    "London",
	"afr-nigeria":  "Lagos",
}

RegionLabel regionlable

View Source
var SdkClient *sdk.Client

SdkClient 用于上报数据

View Source
var UserAgent = fmt.Sprintf("UCloud-CLI/%s", Version)

Functions

func AppendToFile

func AppendToFile(name string, content string) error

AppendToFile 添加到文件中

func Confirm

func Confirm(yes bool, text string) bool

Confirm 二次确认

func FormatDate

func FormatDate(seconds int) string

FormatDate 格式化时间,把以秒为单位的时间戳格式化未年月日

func FormatDateTime

func FormatDateTime(seconds int) string

FormatDateTime 格式化时间,把以秒为单位的时间戳格式化未年月日/时分秒

func GetConfigDir

func GetConfigDir() string

GetConfigDir 获取配置文件所在目录

func GetFileList

func GetFileList(suffix string) []string

GetFileList 补全文件名

func GetHomePath

func GetHomePath() string

GetHomePath 获取家目录

func GetLogFileDir

func GetLogFileDir() string

GetLogFileDir 获取日志文件路径

func GetLogFilePath

func GetLogFilePath() string

GetLogFilePath 获取日志文件路径

func GetLogger

func GetLogger() *log.Logger

GetLogger return point of logger

func GetUserInfo

func GetUserInfo() (*uaccount.UserInfo, error)

GetUserInfo from local file and remote api

func HandleBizError

func HandleBizError(resp response.Common) error

HandleBizError 处理RetCode != 0 的业务异常

func HandleError

func HandleError(err error)

HandleError 处理错误,业务错误 和 HTTP错误

func InitConfig

func InitConfig()

InitConfig 初始化配置

func InitConfigInCloudShell

func InitConfigInCloudShell() error

func IsBase64Encoded

func IsBase64Encoded(data []byte) bool

func LineInFile

func LineInFile(fileName string, lookFor string) bool

LineInFile 检查某一行是否在某文件中

func ListAggConfig

func ListAggConfig(json bool)

ListAggConfig ucloud --config + ucloud config list

func LoadUserInfo

func LoadUserInfo() (*uaccount.UserInfo, error)

LoadUserInfo 从~/.ucloud/user.json加载用户信息

func LogError

func LogError(logs ...string)

LogError 记录日志

func LogInfo

func LogInfo(logs ...string)

LogInfo 记录日志

func LogPrint

func LogPrint(logs ...string)

LogPrint 记录日志

func LogWarn

func LogWarn(logs ...string)

LogWarn 记录日志

func MosaicString

func MosaicString(str string, beginChars, lastChars int) string

MosaicString 对字符串敏感部分打马赛克 如公钥私钥

func ParseError

func ParseError(err error) string

ParseError 解析错误为字符串

func PickResourceID

func PickResourceID(str string) string

PickResourceID uhost-xxx/uhost-name => uhost-xxx

func PrintDescribe

func PrintDescribe(attrs []DescribeTableRow, json bool)

PrintDescribe 打印详情

func PrintJSON

func PrintJSON(dataSet interface{}, out io.Writer) error

PrintJSON 以JSON格式打印数据集合

func PrintList

func PrintList(dataSet interface{}, out io.Writer)

PrintList 打印表格或者JSON

func PrintTable

func PrintTable(dataSet interface{}, fieldList []string)

PrintTable 以表格方式打印数据集合

func PrintTableS

func PrintTableS(dataSet interface{})

PrintTableS 简化版表格打印,无需传表头,根据结构体反射解析

func ToQueryMap

func ToQueryMap(req request.Common) map[string]string

ToQueryMap tranform request to map

func UploadLogs

func UploadLogs(logs []string, level string, goID int64)

UploadLogs send logs to das server

func WriteJSONFile

func WriteJSONFile(list interface{}, filePath string) error

WriteJSONFile 写json文件

Types

type AggConfig

type AggConfig struct {
	Profile        string `json:"profile"`
	Active         bool   `json:"active"`
	ProjectID      string `json:"project_id"`
	Region         string `json:"region"`
	Zone           string `json:"zone"`
	BaseURL        string `json:"base_url"`
	Timeout        int    `json:"timeout_sec"`
	PublicKey      string `json:"public_key"`
	PrivateKey     string `json:"private_key"`
	Cookie         string `json:"cookie"`
	CSRFToken      string `json:"csrf_token"`
	MaxRetryTimes  *int   `json:"max_retry_times"`
	AgreeUploadLog bool   `json:"agree_upload_log"`
}

AggConfig 聚合配置 config+credential

func (*AggConfig) ConfigBaseURL

func (p *AggConfig) ConfigBaseURL() error

ConfigBaseURL 输入BaseURL

func (*AggConfig) ConfigPrivateKey

func (p *AggConfig) ConfigPrivateKey() error

ConfigPrivateKey 输入私钥

func (*AggConfig) ConfigPublicKey

func (p *AggConfig) ConfigPublicKey() error

ConfigPublicKey 输入公钥

func (*AggConfig) ConfigUploadLog

func (p *AggConfig) ConfigUploadLog() error

ConfigUploadLog agree upload log or not

func (*AggConfig) GetClientConfig

func (p *AggConfig) GetClientConfig(isDebug bool) *sdk.Config

GetClientConfig 用来生成sdkClient

func (*AggConfig) GetCredential

func (p *AggConfig) GetCredential() *auth.Credential

GetCredential 用来生成SDkClient

type AggConfigManager

type AggConfigManager struct {
	// contains filtered or unexported fields
}

AggConfigManager 配置管理

func NewAggConfigManager

func NewAggConfigManager(cfgFile, credFile *os.File) (*AggConfigManager, error)

NewAggConfigManager create instance

func NewInCloudShell

func NewInCloudShell() (*AggConfigManager, error)

func (*AggConfigManager) Append

func (p *AggConfigManager) Append(config *AggConfig) error

Append config to list, override if already exist the same profile

func (*AggConfigManager) DeleteByProfile

func (p *AggConfigManager) DeleteByProfile(profile string) error

DeleteByProfile 从AggConfigList和本地文件中删除此配置

func (*AggConfigManager) GetActiveAggConfig

func (p *AggConfigManager) GetActiveAggConfig() (*AggConfig, error)

GetActiveAggConfig get active agg config

func (*AggConfigManager) GetActiveAggConfigName

func (p *AggConfigManager) GetActiveAggConfigName() string

GetActiveAggConfigName get active config name

func (*AggConfigManager) GetAggConfigByProfile

func (p *AggConfigManager) GetAggConfigByProfile(profile string) (*AggConfig, bool)

GetAggConfigByProfile get config of specify profile

func (*AggConfigManager) GetAggConfigList

func (p *AggConfigManager) GetAggConfigList() []AggConfig

GetAggConfigList get all profile config

func (*AggConfigManager) GetProfileNameList

func (p *AggConfigManager) GetProfileNameList() []string

GetProfileNameList 获取所有profiles 用于ucloud config --profile 补全

func (*AggConfigManager) Load

func (p *AggConfigManager) Load() error

Load AggConfigList from local file $HOME/.ucloud/config.json+credential.json

func (*AggConfigManager) Save

func (p *AggConfigManager) Save() error

Save configs to local file

func (*AggConfigManager) UpdateAggConfig

func (p *AggConfigManager) UpdateAggConfig(config *AggConfig) error

UpdateAggConfig update AggConfig append if not exist

type CLIConfig

type CLIConfig struct {
	ProjectID      string `json:"project_id"`
	Region         string `json:"region"`
	Zone           string `json:"zone"`
	BaseURL        string `json:"base_url"`
	Timeout        int    `json:"timeout_sec"`
	Profile        string `json:"profile"`
	Active         bool   `json:"active"` //是否生效
	MaxRetryTimes  *int   `json:"max_retry_times"`
	AgreeUploadLog bool   `json:"agree_upload_log"`
}

CLIConfig cli_config element

type Client

Client aggregate client for business

var BizClient *Client

BizClient 用于调用业务接口

func GetBizClient

func GetBizClient(ac *AggConfig) (*Client, error)

GetBizClient 初始化BizClient

func NewClient

func NewClient(config *sdk.Config, credConfig *CredentialConfig) *Client

NewClient will return a aggregate client

type CredHeader

type CredHeader struct {
	Key   string
	Value []string
}

type CredentialConfig

type CredentialConfig struct {
	PublicKey  string `json:"public_key"`
	PrivateKey string `json:"private_key"`
	Cookie     string `json:"cookie"`
	CSRFToken  string `json:"csrf_token"`
	Profile    string `json:"profile"`
}

CredentialConfig credential element

var AuthCredential *CredentialConfig

AuthCredential 创建sdk client参数

type DescribeTableRow

type DescribeTableRow struct {
	Attribute string
	Content   string
}

DescribeTableRow 详情表格通用表格行

type GlobalFlag

type GlobalFlag struct {
	Debug         bool
	JSON          bool
	Version       bool
	Completion    bool
	Config        bool
	Signup        bool
	Profile       string
	PublicKey     string
	PrivateKey    string
	BaseURL       string
	Timeout       int
	MaxRetryTimes int
}

GlobalFlag 几乎所有接口都需要的参数,例如 region zone projectID

var Global GlobalFlag

Global 全局flag

type LogRotateHook

type LogRotateHook struct {
	MaxSize int64
	Cut     float32
	LogFile *os.File
	// contains filtered or unexported fields
}

LogRotateHook rotate log file

func NewLogRotateHook

func NewLogRotateHook(file *os.File) *LogRotateHook

NewLogRotateHook create a LogRotateHook

func (*LogRotateHook) Fire

func (hook *LogRotateHook) Fire(entry *log.Entry) error

Fire do someting when hook is triggered

func (*LogRotateHook) Levels

func (hook *LogRotateHook) Levels() []log.Level

Levels fires hook

type OldConfig

type OldConfig struct {
	PublicKey  string `json:"public_key"`
	PrivateKey string `json:"private_key"`
	Region     string `json:"region"`
	Zone       string `json:"zone"`
	ProjectID  string `json:"project_id"`
}

OldConfig 0.1.7以及之前版本的配置struct

func (*OldConfig) Load

func (p *OldConfig) Load() error

Load 从本地文件加载配置

type Poller

type Poller struct {
	DescribeFunc  func(string, string, string, string) (interface{}, error)
	Out           io.Writer
	Timeout       time.Duration
	SdescribeFunc func(string) (interface{}, error)
	// contains filtered or unexported fields
}

Poller 轮询器

func NewPoller

func NewPoller(describeFunc func(string, string, string, string) (interface{}, error), out io.Writer) *Poller

NewPoller 轮询

func NewSpoller

func NewSpoller(describeFunc func(string) (interface{}, error), out io.Writer) *Poller

NewSpoller simple

func (*Poller) Poll

func (p *Poller) Poll(resourceID, projectID, region, zone, pollText string, targetState []string) bool

Poll function

func (*Poller) Spoll

func (p *Poller) Spoll(resourceID, pollText string, targetStates []string)

Spoll 简化版

func (*Poller) Sspoll

func (p *Poller) Sspoll(resourceID, pollText string, targetStates []string, block *ux.Block) *pollResult

Sspoll 简化版, 支持并发

type PrivatePathxClient

type PrivatePathxClient = ppathx.PathXClient

PrivatePathxClient 私有模块的pathx client 即未在官网开放的接口

type PrivateUDBClient

type PrivateUDBClient = pudb.UDBClient

PrivateUDBClient 私有模块的udb client 即未在官网开放的接口

type PrivateUHostClient

type PrivateUHostClient = puhost.UHostClient

PrivateUHostClient 私有模块的uhost client 即未在官网开放的接口

type PrivateUMemClient

type PrivateUMemClient = pumem.UMemClient

PrivateUMemClient 私有模块的umem client 即未在官网开放的接口

type Tracer

type Tracer struct {
	DasUrl string
}

Tracer upload log to server if allowed

func (Tracer) Send

func (t Tracer) Send(logs []string) error

Send logs to server

Jump to

Keyboard shortcuts

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