dongyun8138 2014-06-24 17:04
浏览 82

Golang不使用数据库

I don't want to use a DB at this time, I'd like to keep data, as structs, in a file. My question is how to organize and retrieve the data.

For example, I have:

type Foo struct{
 Id int
 Name string
}
type Bar struct{
 Id int
 Name string
}

I want to make a bunch of different Foos and Bars, then I want to be able to query/select particular Foos and Bars. Would I make a package then a file in the package, for instance, foo/foo.go; and in foo.go have a method that makes all of the Foos, then another method that would accept, for example, a name, and then search for that particular Foo.

func MakeFoos(){
 //make the Foos here, and put them in a global array: []Foo ??
}

func GetFoo(name string) Foo{
 //this would search the array populated in MakeFoos() and return a Foo ??
}

Is this an ok start to hold data in memory as opposed to a DB in Go? Any help and suggestions to get me going welcomed.

  • 写回答

1条回答 默认 最新

  • doucheng7808 2014-06-25 19:36
    关注

    I am working on a GO project that does not use a database. Using slices, maps, linked lists, json, and the OS file system quite a bit can be accomplished without a database. I don't have a solution for you, but study up on the tools I just mentioned. All these tools are included in the standard Go libraries.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器