Skip to content

Instantly share code, notes, and snippets.

@Starttoaster
Created September 20, 2019 14:37
Show Gist options
  • Save Starttoaster/0087173e77b14b4cd88038457a8c66c5 to your computer and use it in GitHub Desktop.
Save Starttoaster/0087173e77b14b4cd88038457a8c66c5 to your computer and use it in GitHub Desktop.
Sample Scribble DB usage
package main
import (
"github.com/nanobox-io/golang-scribble"
"fmt"
)
type Auth struct{ Token string }
//Declaring variables..
var myTokenContents string = "ThIsIsMyTokEnz"
var dbName string = "auth"
var tableName string = "session"
var tableRow string = "token"
//Create table
var db, _ = scribble.New(dbName, nil)
//Writes the "myTokenContents" variable to "./auth/session/token.json" as type "Auth"
func writeToTable(tokenContents string) {
db.Write(tableName, tableRow, Auth{Token: tokenContents,})
}
//Reads the token.json file and returns the token as string
func readTable() string {
currentToken := Auth{}
db.Read(tableName, tableRow, &currentToken)
return currentToken.Token
}
func main() {
writeToTable(myTokenContents)
fmt.Println(readTable())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment