栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

接口命名约定Golang

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

接口命名约定Golang

我知道了,事实证明我可以使用“ er”约定。

package goserverconst (    ROLE_KEY string = "role")type Role string//if index is higher or equal than role, will passtype RolesHierarchy []Roletype RoleChecker interface {    IsRole(Role, RolesHierarchy) bool}type RoleAssumer interface {    AssumeRole(ServerSession, Role)}type RoleCheckerAssumer interface {    RoleChecker    RoleAssumer}func (r Role) String() string {    return string(r)}func NewRole(session ServerSession) Role {    return session.GetValue(ROLE_KEY).(Role)}func (this Role) IsRole(role Role, hierarchy RolesHierarchy) bool {    if role == this {        return true    }    if len(hierarchy) == 0 {        return false    }    var thisI int = 0    var roleI int = 0    //Duped roles in hierarchy are verified in verifyConfig during parse    for i, r := range hierarchy {        if this == r { thisI = i        }        if role == r { roleI = i        }    }    //TODO I can probably condense what follows into one if    if thisI == 0 && roleI == 0 {        return false    }    return thisI >= roleI}func (this *Role) AssumeRole(session ServerSession, role Role) {   session.SetValue(ROLE_KEY, role)   *this = role}

谢谢Sarathsp,让我正确地考虑了这一点。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/568954.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号