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 ( import (
"encoding/json" "encoding/json"
@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"legendsbrowser/util"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
@ -16,6 +15,7 @@ import (
"text/template" "text/template"
"github.com/iancoleman/strcase" "github.com/iancoleman/strcase"
"github.com/robertjanetzko/LegendsBrowser2/backend/util"
) )
func Analyze(filex string) { func Analyze(filex string) {

View File

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

View File

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