Upload files to "v1"
This commit is contained in:
48
v1/extra.go
Normal file
48
v1/extra.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package extra
|
||||
|
||||
import (
|
||||
"angel_server/consts"
|
||||
"angel_server/cryptmeow"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func Init() {
|
||||
consts.Logger.Warn("Welcome to angel net! To autheticate as the admin controller of the net, you'll need to use the following key via the ssh shell")
|
||||
consts.Logger.Warn(fmt.Sprintf("%d", cryptmeow.ControllerPublicKey[:]))
|
||||
|
||||
var err error
|
||||
consts.Db, err = sql.Open("sqlite3", "../angel_db.sqlite3")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer consts.Db.Close()
|
||||
|
||||
createTableSQL := `
|
||||
CREATE TABLE IF NOT EXISTS layers (
|
||||
layer_id INTEGER NOT NULL CHECK(layer_id >= 0 AND layer_id <= 8),
|
||||
public_key BLOB NOT NULL CHECK(LENGTH(public_key) = 32),
|
||||
secret_key BLOB NOT NULL CHECK(LENGTH(secret_key) = 32),
|
||||
PRIMARY KEY (layer_id)
|
||||
);`
|
||||
|
||||
_, err = consts.Db.Exec(createTableSQL)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var array_pk, array_sk []byte
|
||||
copy(array_pk, cryptmeow.ControllerPublicKey[:])
|
||||
copy(array_sk, cryptmeow.ControllerPrivateKey[:])
|
||||
|
||||
insertSQL := `INSERT OR IGNORE INTO layers (layer_id, public_key, secret_key) VALUES (?, ?, ?);`
|
||||
_, err = consts.Db.Exec(insertSQL, 0, array_pk, array_sk)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
consts.Logger.Info("Database initialized and 'layers' table created successfully! Admin/controller handler has been added.")
|
||||
}
|
||||
Reference in New Issue
Block a user