package main import ( "errors" "math/rand" "os" "github.com/br0xen/boltrest" ) var adminDB *boltrest.DB func main() { initialize() adminDB = boltrest.Open("admin.db") } func mainLoop() { } func initialize() error { // Make sure that the necessary files/directories are in place var tstDir *os.File var tstDirInfo os.FileInfo var err error if tstDir, err = os.Open("dbs"); err != nil { if err = os.Mkdir("dbs", 0755); err != nil { return err } if tstDir, err = os.Open("dbs"); err != nil { return err } } if tstDirInfo, err = tstDir.Stat(); err != nil { return err } if !tstDirInfo.IsDir() { return errors.New("'dbs' exists and is not a directory") } // We were able to open the db path and it was a directory return nil } const keyChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" func generateAPIKey() string { b := make([]byte, 34) for i := range b { if i%5 == 4 { b[i] = '-' } else { b[i] = keyChars[rand.Int63()%int64(len(keyChars))] } } return string(b) }