-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
50 lines (41 loc) · 941 Bytes
/
Copy pathutils.go
File metadata and controls
50 lines (41 loc) · 941 Bytes
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
package main
import (
"encoding/json"
"fmt"
"io"
"os"
)
type SiteConfigNavElement struct {
Title string `json:"title"`
Href string `json:"href"`
}
type SiteConfig struct {
Name string `json:"name"`
Theme string `json:"theme"`
NavElements []SiteConfigNavElement `json:"nav-elements"`
}
type MetadataEntry struct {
key string
value string
}
func ReadConfig() SiteConfig {
siteConfigFile, err := os.Open(fmt.Sprintf("site.json"))
if err != nil {
fmt.Println("ERROR: Failed to open site.json")
}
defer siteConfigFile.Close()
// unmarshal json and then return
siteConfigData, _ := io.ReadAll(siteConfigFile)
var siteConfig SiteConfig
err = json.Unmarshal(siteConfigData, &siteConfig)
if err != nil {
fmt.Println("ERROR: Failed to parse site.json")
}
return siteConfig
}
func If[T any](cond bool, vtrue, vfalse T) T {
if cond {
return vtrue
}
return vfalse
}