我开发Sinatra应用程序并在那里使用ActiveRecord来处理数据库,但我遇到了一个问题.我为一个模型写了一个测试,它打破了
SQLite3 :: CantOpenException:无法打开数据库文件
使用以下代码在test_helper.rb中建立与数据库的连接:
Dir.chdir('..') do
ActiveRecord::Base.establish_connection(db_config)
end
Run Code Online (Sandbox Code Playgroud)
并ActiveRecord::Base.connected?得到假.如果我User.find(:all)在连接建立测试之后调用将会通过并且ActiveRecord::Base.connected?将为真.为什么?我不明白.
我有以下代码:
package main
import (
"fmt"
)
type Point struct {
x,y int
}
func decode(value interface{}) {
fmt.Println(value) // -> &{0,0}
// This is simplified example, instead of value of Point type, there
// can be value of any type.
value = &Point{10,10}
}
func main() {
var p = new(Point)
decode(p)
fmt.Printf("x=%d, y=%d", p.x, p.y) // -> x=0, y=0, expected x=10, y=10
}
Run Code Online (Sandbox Code Playgroud)
我想将任何类型的值设置为传递给decode函数的值.Go是可能的,还是我误解了什么?