小编Dal*_*ale的帖子

接口命名约定Golang

我只是发布我的代码:

/*
*  Role will ALWAYS reserve the session key "role".
 */
package goserver

const (
    ROLE_KEY string = "role"
)

type Role string

//if index is higher or equal than role, will pass
type RolesHierarchy []Role

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 …
Run Code Online (Sandbox Code Playgroud)

naming interface naming-conventions go

15
推荐指数
2
解决办法
2万
查看次数

一棵树,每个节点可以有多个父节点

这是一个理论/迂腐的问题:想象一下属性,其中每个属性可以由多个其他人拥有.此外,从所有权的一次迭代到下一次,两个邻近的所有者可以决定部分地结合所有权.例如:

territory 1, t=0: a,b,c,d
territory 2, t=0: e,f,g,h

territory 1, t=1: a,b,g,h
territory 2, t=1: g,h
Run Code Online (Sandbox Code Playgroud)

也就是说,cd不再拥有自己的财产; 可以这么说g,h成了肥猫.

我目前将这个数据结构表示为一个树,每个孩子可以有多个父母.我的目标是将其融入复合设计模式中; 但我遇到的问题是如何在客户可能会回过头来更新以前的所有权而不会破坏整个结构.

我的问题是双重的.

  1. 简单:这个数据结构有什么方便的名称,这样我可以自己谷歌吗?

  2. 辛苦:我做错了什么?当我编码时,我试着保持口头禅,"保持简单,愚蠢",在我脑海里,我觉得我打破了这个信条.

oop tree design-patterns graph-theory composite

9
推荐指数
1
解决办法
1万
查看次数

get_user_by() 在 wordpress 中未定义

因此,我正在编写一个插件,用于解析 json feed 并从 feed 以编程方式生成页面。我想以编程方式创建一个用户,该用户将成为页面的作者。问题是当我username_exists()在内部调用这个函数时get_user_by(),它最终是未定义的。我的猜测是我需要执行一些操作或需要首先完成一些其他事件,但我不知所措。这是代码,apache 抛出的错误是:

/**
 * A simple class for the cron user, ie the 'author' that will
 * generate pages from the feed
*/
class PP_CronUser {

  private static $cronUserName = 'Cron User';
  private static $cronEmail = 'asdf';
  private static $cronPW = 'asdf';
  private static $ID = null;

  public static function getUserID() {
    if(!is_null(self::$ID)) return self::$ID;
    if(!($id = username_exists(self::$cronUserName))) { //Here's the offending line
    self::$ID = $id;
    return $id;
    }   
    self::$ID = …
Run Code Online (Sandbox Code Playgroud)

php wordpress

2
推荐指数
2
解决办法
1万
查看次数

分配的值,不在if语句中使用

我写了一个我在游乐场看到的问题的例子:https: //play.golang.org/p/rPCqAC56Ff

这很明显,但是我在if语句之外声明一个变量,在if中设置变量然后在if之外使用.

问题很简单,为什么这不起作用?

package main

import (
    "fmt"
    "os"
)

func main() {
    var foo string
    if true {
        foo = "foo"
    } else {
        foo, found := os.LookupEnv("GOPATH")
        if !found {
            fmt.Printf("who cares.\n")
        }
    }
    println(foo)
}
Run Code Online (Sandbox Code Playgroud)

go

-1
推荐指数
1
解决办法
126
查看次数