restructure

This commit is contained in:
Robert Janetzko 2022-04-14 13:58:28 +00:00
parent 06a89e467b
commit 77b720f8d2
18 changed files with 19 additions and 77 deletions

5
analyze/go.mod Normal file
View file

@ -0,0 +1,5 @@
module github.com/robertjanetzko/LegendsBrowser2/analyze
go 1.18
require github.com/iancoleman/strcase v0.2.0

2
analyze/go.sum Normal file
View file

@ -0,0 +1,2 @@
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=

View file

@ -1,4 +1,4 @@
package analyze
package main
import (
"encoding/json"
@ -6,7 +6,6 @@ import (
"fmt"
"io"
"io/ioutil"
"legendsbrowser/util"
"log"
"os"
"path/filepath"
@ -16,6 +15,7 @@ import (
"text/template"
"github.com/iancoleman/strcase"
"github.com/robertjanetzko/LegendsBrowser2/backend/util"
)
func Analyze(filex string) {

View file

@ -1,4 +1,4 @@
module legendsbrowser
module github.com/robertjanetzko/LegendsBrowser2/backend
go 1.18

View file

@ -3,7 +3,6 @@ package main
import (
"flag"
"fmt"
"legendsbrowser/analyze"
"legendsbrowser/df"
"legendsbrowser/server"
"net/http"
@ -18,18 +17,18 @@ import (
var world *df.DfWorld
func main() {
a := flag.String("a", "", "analyze a file")
g := flag.Bool("g", false, "generate model")
// a := flag.String("a", "", "analyze a file")
// g := flag.Bool("g", false, "generate model")
f := flag.String("f", "", "open a file")
flag.Parse()
if len(*a) > 0 {
analyze.Analyze(*a)
}
if *g {
fmt.Println("Generating")
analyze.Generate()
}
// if len(*a) > 0 {
// analyze.Analyze(*a)
// }
// if *g {
// fmt.Println("Generating")
// analyze.Generate()
// }
if len(*f) > 0 {
defer profile.Start(profile.MemProfile).Stop()

View file

@ -1,64 +0,0 @@
package generate
import (
"bufio"
"log"
"net/http"
"os"
"strings"
"text/template"
"time"
)
func Generate() {
const url = "https://github.com/golang/go/raw/master/CONTRIBUTORS"
rsp, err := http.Get(url)
die(err)
defer rsp.Body.Close()
sc := bufio.NewScanner(rsp.Body)
carls := []string{}
for sc.Scan() {
if strings.Contains(sc.Text(), "Carl") {
carls = append(carls, sc.Text())
}
}
die(sc.Err())
f, err := os.Create("contributors.go")
die(err)
defer f.Close()
packageTemplate.Execute(f, struct {
Timestamp time.Time
URL string
Carls []string
}{
Timestamp: time.Now(),
URL: url,
Carls: carls,
})
}
func die(err error) {
if err != nil {
log.Fatal(err)
}
}
var packageTemplate = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// {{ .Timestamp }}
// using data from
// {{ .URL }}
package project
var Contributors = []string{
{{- range .Carls }}
{{ printf "%q" . }},
{{- end }}
}
`))