import cycle not allowed

package demo/model
	imports demo/model/demos
	imports demo/model

在进行 go run 或者go build 时出现上面的错误,
go 中不允许包与包之间互相引用,在项目中进行包规划时要注意。

示例代码:

model.go

package model

import (
	"demo/model/demos"
	"fmt"
)

var VariableA = demos.A{}

func init() {
	VariableA.N = 12
	println("inital model")
}

func Do() {
	fmt.Printf("model: works\n")
	fmt.Printf("VariableA: %+v\n", VariableA)

}

demos.go

package demos

import (
"demo/model"
)

type A struct {
	N int
}

func (this A) Demo() {
	println("in model!!!! a's demo'", this.N)
	fmt.Printf("model.VariableA: %+v\n", model.VariableA)
}

main.go

package main

import (
	"demo/model"
)

func main() {
	model.Do()
}

2015-08-30