evaluator: Directly parse yaml file

This commit is contained in:
Simon Bruder 2021-01-04 22:10:39 +01:00
parent 3304bf1b49
commit 01330f405c
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
5 changed files with 11 additions and 5 deletions

2
.gitignore vendored
View file

@ -1 +1 @@
bangs.json /evaluator/vendor/

View file

@ -13,7 +13,7 @@ RUN go get -v \
FROM scratch FROM scratch
COPY --from=builder /go/src/git.sbruder.de/simon/bangs/evaluator/evaluator /evaluator COPY --from=builder /go/src/git.sbruder.de/simon/bangs/evaluator/evaluator /evaluator
copy bangs.json /bangs.json COPY bangs.yml /bangs.yml
USER 1000 USER 1000

View file

@ -1,13 +1,14 @@
package main package main
import ( import (
"encoding/json"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
"regexp" "regexp"
"strings" "strings"
"gopkg.in/yaml.v2"
) )
var bangs = loadBangs() var bangs = loadBangs()
@ -32,12 +33,12 @@ func main() {
} }
func loadBangs() (bangs map[string]string) { func loadBangs() (bangs map[string]string) {
data, err := ioutil.ReadFile("bangs.json") data, err := ioutil.ReadFile("bangs.yml")
if err != nil { if err != nil {
log.Fatalf("Failed to read bangs: %v", err) log.Fatalf("Failed to read bangs: %v", err)
} }
err = json.Unmarshal(data, &bangs) err = yaml.Unmarshal(data, &bangs)
if err != nil { if err != nil {
log.Fatalf("Failed to decode bangs: %v", err) log.Fatalf("Failed to decode bangs: %v", err)
} }

View file

@ -1,3 +1,5 @@
module git.sbruder.de/simon/bangs/evaluator module git.sbruder.de/simon/bangs/evaluator
go 1.15 go 1.15
require gopkg.in/yaml.v2 v2.4.0

3
evaluator/go.sum Normal file
View file

@ -0,0 +1,3 @@
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=