Reformat the way I like it
This commit is contained in:
parent
f313a8f1c9
commit
75732476be
1 changed files with 17 additions and 25 deletions
42
main.go
42
main.go
|
@ -18,21 +18,13 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
useClient := flag.Bool("c", false, "Run client")
|
useClient := flag.Bool("c", false, "Run client")
|
||||||
|
|
||||||
keyId := flag.String("id", "", "The key id to pass")
|
keyId := flag.String("id", "", "The key id to pass")
|
||||||
|
|
||||||
register := flag.Bool("r", false, "Register a key")
|
register := flag.Bool("r", false, "Register a key")
|
||||||
|
|
||||||
user := flag.String("user", "", "Username to register")
|
user := flag.String("user", "", "Username to register")
|
||||||
|
|
||||||
keyPath := flag.String("key", "", "Path to the private key (client mode) or public key (registration mode) to use")
|
keyPath := flag.String("key", "", "Path to the private key (client mode) or public key (registration mode) to use")
|
||||||
|
|
||||||
baseUrlString := flag.String("base-url", "http://localhost:8080", "Base URL of the server")
|
baseUrlString := flag.String("base-url", "http://localhost:8080", "Base URL of the server")
|
||||||
|
|
||||||
simulateCaddy := flag.Bool("caddy", false, "Simulate caddy reverse proxy")
|
simulateCaddy := flag.Bool("caddy", false, "Simulate caddy reverse proxy")
|
||||||
|
|
||||||
useTempDb := flag.Bool("temp-db", false, "Use a temporary in-memory database")
|
useTempDb := flag.Bool("temp-db", false, "Use a temporary in-memory database")
|
||||||
|
|
||||||
dbPath := flag.String("db", "", "Path to the sqlite database file")
|
dbPath := flag.String("db", "", "Path to the sqlite database file")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@ -97,23 +89,6 @@ func runClient(baseUrl *url.URL, keyFile string, keyId string, simulateCaddy boo
|
||||||
fmt.Println(string(out[:]))
|
fmt.Println(string(out[:]))
|
||||||
}
|
}
|
||||||
|
|
||||||
func runServer(simulateCaddy bool, useTempDb bool, dbPath string) {
|
|
||||||
var keyDir keydirectory.RegistrationDirectory
|
|
||||||
|
|
||||||
if useTempDb {
|
|
||||||
keyDir = keydirectory.CreateMemoryDirectory()
|
|
||||||
} else {
|
|
||||||
var err error
|
|
||||||
keyDir, err = keydirectory.InitSqlite(dbPath)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
server.Start(simulateCaddy, keyDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadPrivateKey(keyFile string) (crypto.PrivateKey, error) {
|
func loadPrivateKey(keyFile string) (crypto.PrivateKey, error) {
|
||||||
keyBytes, err := os.ReadFile(keyFile)
|
keyBytes, err := os.ReadFile(keyFile)
|
||||||
|
|
||||||
|
@ -139,3 +114,20 @@ func registerKey(baseUrl *url.URL, keyFile string, userId string) {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runServer(simulateCaddy bool, useTempDb bool, dbPath string) {
|
||||||
|
var keyDir keydirectory.RegistrationDirectory
|
||||||
|
|
||||||
|
if useTempDb {
|
||||||
|
keyDir = keydirectory.CreateMemoryDirectory()
|
||||||
|
} else {
|
||||||
|
var err error
|
||||||
|
keyDir, err = keydirectory.InitSqlite(dbPath)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server.Start(simulateCaddy, keyDir)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue