- 结构体初始化
- 结构体方法调用
package main
import (
"fmt"
)
type SecLimit struct {
a string
b string
}
type SecLimitMgr struct {
UserLimitMap map[int]*SecLimit
}
// 限制器
func antiSpam(req *SecRequest) (err error) {
seclimt, ok := SecLimitMgr.UserLimitMap[req.UserId] //
// 未获取到值
if !ok {
seclimt = &SecLimit{} // 初始化结构体
SecLimitMgr.UserLimitMap[req.UserId] = seclimt
}
count := SecLimit.Count() // 调用结构体的方法
}
// SecLimit结构体的一个方法
func (s *SecLimit) Count() error {
// 方法体
}