common

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CryptoRandomHex

func CryptoRandomHex(len int) (string, error)

CryptoRandomHex 生成16进制随机数

func GetEmailFromAccessToken

func GetEmailFromAccessToken(token *string) (string, error)

func NewRedisClient

func NewRedisClient() (*redis.Client, error)

func Pub

func Pub(client *redis.Client, channel string, payload string) error

func ReadINI

func ReadINI(iniPath string) (map[string]string, error)

Sample: vaultConf := "/login/vault/vault.conf" vaultProps, err := ReadINI(vaultConf) endpoint := vaultProps["endpoint"]

if os.IsNotExist(err) || strings.TrimSpace(endpoint) == "" {
	beego.Info("getVaultInstance ", err)
	panic("please check vault properties")
}

ReadINI read ini file into map

func Sub

func Sub(pubsub *redis.PubSub, persist bool, f func(string)) error

func TriggerSlack

func TriggerSlack(slackToken, channelName, text string, blocks []*Blocks) error

blocks sample:

titleBlock := &Blocks{
	Type: "section",
	Text: &TextPayload{
		Type: "mrkdwn",
		Text: "*Bastionhost bastionhost-sample installation complete*",
	},
}
bodyBlock := &Blocks{
	Type: "section",
	Text: &TextPayload{
		Type: "mrkdwn",
		Text: "ClusterID: bp59t7fd0ttl3j541hng\nClusterName: OSSTestDal13\nLogin URL: `tsh login --proxy osstestdal13-0278914c3cb0e2be944d47de59947e32-0039.us-south.containers.appdomain.cloud:443`",
	},
}

blocks := make([]*Blocks, 0) blocks = append(blocks, titleBlock) blocks = append(blocks, bodyBlock)

func TriggerSlackOutdated

func TriggerSlackOutdated(slackToken string, legacySlackMsg *LegacySlackMsg) error

Types

type Blocks

type Blocks struct {
	Type string       `json:"type"`
	Text *TextPayload `json:"text"`
}

type LegacyAttachment

type LegacyAttachment struct {
	MrkdwnIn   []string       `json:"mrkdwn_in"`
	Color      string         `json:"color"`
	Pretext    string         `json:"pretext"`
	AuthorName string         `json:"author_name"`
	AuthorIcon string         `json:"author_icon"`
	Title      string         `json:"title"`
	Text       string         `json:"text"`
	Fields     []*LegacyField `json:"fields"`
	ThumbURL   string         `json:"thumb_url"`
}

type LegacyField

type LegacyField struct {
	Title string `json:"title"`
	Value string `json:"value"`
	Short bool   `json:"short"`
}

type LegacySlackMsg

type LegacySlackMsg struct {
	Channel     string              `json:"channel"`
	Text        string              `json:"text"`
	Attachments []*LegacyAttachment `json:"attachments"`
}

type Payload

type Payload struct {
	AsUser  bool      `json:"as_user"`
	Mrkdwn  bool      `json:"mrkdwn"`
	Channel string    `json:"channel"`
	Text    string    `json:"text"`
	Blocks  []*Blocks `json:"blocks"`
}

type TextPayload

type TextPayload struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

Jump to

Keyboard shortcuts

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