Created
September 20, 2019 14:37
-
-
Save Starttoaster/0087173e77b14b4cd88038457a8c66c5 to your computer and use it in GitHub Desktop.
Sample Scribble DB usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, ¤tToken) | |
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