This commit is contained in:
Robert Janetzko 2022-04-10 21:27:37 +00:00
parent 5d5ae57cc9
commit ef5c2ca337
6 changed files with 31 additions and 6 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
region*.xml region*.xml
legendsbrowser legendsbrowser
*.pprof
*.png

2
go.mod
View File

@ -5,5 +5,5 @@ go 1.18
require ( require (
github.com/gorilla/mux v1.8.0 github.com/gorilla/mux v1.8.0
github.com/iancoleman/strcase v0.2.0 github.com/iancoleman/strcase v0.2.0
github.com/sa-/slicefunk v0.1.2 github.com/pkg/profile v1.6.0
) )

4
go.sum
View File

@ -2,5 +2,5 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/sa-/slicefunk v0.1.2 h1:uTQiyKCTwc0RKNxXmG6NNlm3J1LF2hKmLgtf9kRAld4= github.com/pkg/profile v1.6.0 h1:hUDfIISABYI59DyeB3OTay/HxSRwTQ8rB/H83k6r5dM=
github.com/sa-/slicefunk v0.1.2/go.mod h1:k0abNpV9EW8LIPl2+Hc9RiKsojKmsUhNNGFyMpjMTCI= github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18=

12
main.go
View File

@ -5,16 +5,26 @@ import (
"legendsbrowser/model" "legendsbrowser/model"
"legendsbrowser/server" "legendsbrowser/server"
"net/http" "net/http"
_ "net/http/pprof"
"runtime"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/pkg/profile"
) )
var world model.World var world model.World
func main() { func main() {
defer profile.Start(profile.MemProfile).Stop()
go func() {
http.ListenAndServe(":8081", nil)
}()
fmt.Println("Hallo Welt!") fmt.Println("Hallo Welt!")
world.Load("region1-00152-01-01-legends.xml") // world.Load("region1-00152-01-01-legends.xml")
world.Load("region2-00195-01-01-legends.xml")
runtime.GC()
world.Process() world.Process()
model.ListOtherElements(&world.HistoricalEvents) model.ListOtherElements(&world.HistoricalEvents)

View File

@ -3,7 +3,7 @@ package model
import ( import (
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"io/ioutil" "io"
"os" "os"
"reflect" "reflect"
) )
@ -36,6 +36,10 @@ type World struct {
EntityMap map[int]*Entity EntityMap map[int]*Entity
} }
var cp437 = []byte(" \t\n \r !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ CueaaaaceeeiiiAAEaAooouuyOU faiounN ")
// var cp437 = []byte(" \t\n \r !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñÑ ")
func (w *World) Load(file string) { func (w *World) Load(file string) {
xmlFile, err := os.Open(file) xmlFile, err := os.Open(file)
if err != nil { if err != nil {
@ -45,9 +49,14 @@ func (w *World) Load(file string) {
fmt.Println("Successfully Opened users.xml") fmt.Println("Successfully Opened users.xml")
defer xmlFile.Close() defer xmlFile.Close()
byteValue, _ := ioutil.ReadAll(xmlFile) byteValue, _ := io.ReadAll(xmlFile)
fmt.Println(len(byteValue)) fmt.Println(len(byteValue))
copy(byteValue[30:35], []byte("UTF-8"))
for i := range byteValue {
byteValue[i] = cp437[byteValue[i]]
}
err = xml.Unmarshal(byteValue, w) err = xml.Unmarshal(byteValue, w)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)

4
sample.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
curl http://localhost:8081/debug/pprof/heap > heap.0.pprof
go tool pprof heap.0.pprof