Starting work on server
This commit is contained in:
2
boltrest-server/.gitignore
vendored
Normal file
2
boltrest-server/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# Server Binary
|
||||
boltrest-server
|
53
boltrest-server/main.go
Normal file
53
boltrest-server/main.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/rand"
|
||||
"os"
|
||||
|
||||
"github.com/br0xen/boltrest"
|
||||
)
|
||||
|
||||
var adminDB *boltrest.DB
|
||||
|
||||
func main() {
|
||||
initialize()
|
||||
adminDB = boltrest.Open("admin.db")
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
Reference in New Issue
Block a user