package jwt type DataClaims map[string]string const ( idCode = "id" roleCode = "role" deviceIDCode = "device_id" scopeCode = "scope" uidCode = "uid" ) // ============ 使用具體的 setter ============ // Set 通用的 setter 方法 func (c DataClaims) Set(key, value string) { c[key] = value } func (c DataClaims) SetID(id string) { c.Set(idCode, id) } func (c DataClaims) SetRole(role string) { c.Set(roleCode, role) } func (c DataClaims) SetDeviceID(deviceID string) { c.Set(deviceIDCode, deviceID) } func (c DataClaims) SetScope(scope string) { c.Set(scopeCode, scope) } func (c DataClaims) SetUID(uid string) { c.Set(uidCode, uid) } // ============ 使用具體的 getter ============ func (c DataClaims) Get(key string) string { if val, ok := c[key]; ok { return val } return "" } func (c DataClaims) Scope() { c.Get(scopeCode) } func (c DataClaims) Role() string { return c.Get(roleCode) } func (c DataClaims) ID() string { return c.Get(idCode) } func (c DataClaims) DeviceID() string { return c.Get(deviceIDCode) } func (c DataClaims) UID() string { return c.Get(uidCode) }