golang 基本语法操作


struct

type Response struct {
    DMErr    int    `json:"dm_error"`
    ErrorMsg string `json:"error_msg"`
    Response string `json:"response"`
}

color

fmt.Printf("%c[0;40;33m", 0x1B)
...
fmt.Printf("%c[0m", 0x1B)

connect number

    body, _ := ioutil.ReadAll(request.Body)
    connect_num := crc32.ChecksumIEEE([]byte(string(body) + time.Now().String()))

json <–> struct

// decode
body, _ := ioutil.ReadAll(request.Body)
var getBody []GetBody
if err := json.Unmarshal(body, &getBody); err != nil {
    log.Errorf("<%d> transcode get, body Unmarshal error:%v", connect_num, err)
    return
}

//encode
responseStr, _ := json.Marshal(resData)
string(responseStr)

replace

srp := strings.NewReplacer("{liveid}", liveinfo.Id)
urlStr = srp.Replace(urlStr)

string to int

uid, err := strconv.ParseUint(uidStr, 10, 64)
if err != nil {
    log.Info("uid ParseUint error, err:", err)
}

strconv.Itoa(policy_int)
strconv.Atoi(policy_str)

other

ids_str = strings.Join(ids_arr_str, ",")
version_arr := strings.Split(version_str, ".")

lock

type UserRightST struct {
    Policy          map[int]PolicyST
    PolicyMutex     sync.RWMutex
}

var UserRight          UserRightST

UserRight.PolicyMutex.Lock()
UserRight.Policy = policyConfig.Policy
UserRight.PolicyMutex.Unlock()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值