-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (36 loc) · 818 Bytes
/
main.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
package main
import (
"fmt"
"gopkg.in/yaml.v3"
"log"
"net/http"
"os"
"time"
)
type ServerConfig struct {
Port int `yaml:"port"`
ServerPath string `yaml:"server_path"`
StaticContent *struct {
RootPath string `yaml:"root_path"`
IndexName string `yaml:"index_name"`
} `yaml:"static_content"`
}
func main() {
f, err := os.ReadFile("config.yaml")
if err != nil {
log.Fatal(err)
}
serverConfig := ServerConfig{}
err = yaml.Unmarshal(f, &serverConfig)
if err != nil {
log.Fatal(err)
}
s := &http.Server{
Addr: fmt.Sprintf(":%d", serverConfig.Port),
Handler: http.FileServer(http.Dir(serverConfig.StaticContent.RootPath)),
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
log.Fatal(s.ListenAndServe())
}