Golang의 작은 JSON 데이터베이스
go get github.com/nanobox-io/golang-scribble
사용하여 설치하세요.
// a new scribble driver, providing the directory where it will be writing to,
// and a qualified logger if desired
db , err := scribble . New ( dir , nil )
if err != nil {
fmt . Println ( "Error" , err )
}
// Write a fish to the database
fish := Fish {}
if err := db . Write ( "fish" , "onefish" , fish ); err != nil {
fmt . Println ( "Error" , err )
}
// Read a fish from the database (passing fish by reference)
onefish := Fish {}
if err := db . Read ( "fish" , "onefish" , & onefish ); err != nil {
fmt . Println ( "Error" , err )
}
// Read all fish from the database, unmarshaling the response.
records , err := db . ReadAll ( "fish" )
if err != nil {
fmt . Println ( "Error" , err )
}
fishies := [] Fish {}
for _ , f := range records {
fishFound := Fish {}
if err := json . Unmarshal ([] byte ( f ), & fishFound ); err != nil {
fmt . Println ( "Error" , err )
}
fishies = append ( fishies , fishFound )
}
// Delete a fish from the database
if err := db . Delete ( "fish" , "onefish" ); err != nil {
fmt . Println ( "Error" , err )
}
// Delete all fish from the database
if err := db . Delete ( "fish" , "" ); err != nil {
fmt . Println ( "Error" , err )
}
낙서에 대한 기여를 환영하고 장려합니다. Scribble은 Nanobox 프로젝트이며 기여는 Nanobox 기여 프로세스 및 지침을 따라야 합니다.