-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (35 loc) · 928 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
42
package main
import (
"log"
"net/http"
"os"
urlshortener "github.com/kuhlman-labs/url-shortener/url-shortener"
"gopkg.in/yaml.v3"
)
type Config struct {
TemplatePath string `yaml:"template_path"`
Port string `yaml:"port"`
Domain string `yaml:"domain"`
}
func main() {
// Read the config.yaml file
data, err := os.ReadFile("config.yaml")
if err != nil {
log.Fatalf("Error reading config.yaml: %v", err)
}
var config Config
err = yaml.Unmarshal(data, &config)
if err != nil {
log.Fatalf("Error unmarshalling config.yaml: %v", err)
}
// Create a new SQL URL repository
db, err := urlshortener.NewSQLURLRepository()
if err != nil {
log.Fatalf("Error creating SQL URL repository: %v", err)
}
// Start the URL handler
err = http.ListenAndServe(":"+config.Port, urlshortener.URLHandler(db, config.TemplatePath))
if err != nil {
log.Fatalf("Error starting URL handler: %v", err)
}
}