bmw0128
bmw0128

Reputation: 13698

Golang not using a DB

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.

Upvotes: 1

Views: 758

Answers (1)

Jay Poss
Jay Poss

Reputation: 21

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.

Upvotes: 1

Related Questions