-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebserver.go
51 lines (45 loc) · 1.23 KB
/
webserver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"embed"
"fmt"
"io/fs"
"io/ioutil"
"log"
"net/http"
"github.com/gmemstr/nas/authentication"
"github.com/gmemstr/nas/files"
"github.com/gmemstr/nas/router"
"github.com/go-yaml/yaml"
)
//go:embed assets/web/*
var sc embed.FS
// Main function that defines routes
func main() {
// Initialize file providers.
file, err := ioutil.ReadFile("providers.yml")
if err != nil {
fmt.Println("Unable to read providers.yml file, does it exist?")
}
err = yaml.Unmarshal(file, &files.ProviderConfig)
if err != nil {
fmt.Println("Unable to parse providers.yml file, is it correct?")
}
files.SetupProviders()
// Initialize auth if set up.
authConfig, err := ioutil.ReadFile("auth.yml")
if err != nil {
fmt.Println("!! No Keycloack configuration found !!\n!! Requests will be unauthenticated !!")
router.AuthEnabled = false
} else {
err = yaml.Unmarshal(authConfig, &authentication.AuthConfig)
if err != nil {
fmt.Println("Unable to parse auth.yml file, is it correct?")
router.AuthEnabled = false
}
fmt.Println("Keycloak configured")
}
fsys, err := fs.Sub(sc, "assets/web")
r := router.Init(fsys)
fmt.Println("Your sliproad instance is live on port :3000")
log.Fatal(http.ListenAndServe(":3000", r))
}