From 0bf58dba2bec78ac59fe0acc5011c0671a56019b Mon Sep 17 00:00:00 2001 From: stevenhowes <38082088+stevenhowes@users.noreply.github.com> Date: Thu, 13 Jan 2022 22:20:08 +0000 Subject: [PATCH] Initial commit of example code for PakGo --- Makefile | 18 ++++++++++++++++ README.md | 1 + example.pak | Bin 0 -> 262 bytes go.mod | 10 +++++++++ go.sum | 2 ++ main.go | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 92 insertions(+) create mode 100644 Makefile create mode 100644 README.md create mode 100644 example.pak create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1d83af6 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +.DEFAULT_GOAL := build + +fmt: + go mod tidy + go fmt ./... +.PHONY:fmt + +lint: fmt + golint ./... +.PHONY:lint + +vet: fmt + go vet ./... +.PHONY:vet + +build: vet + go build +.PHONY:build diff --git a/README.md b/README.md new file mode 100644 index 0000000..6711e10 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Docs coming in next couple of days.. \ No newline at end of file diff --git a/example.pak b/example.pak new file mode 100644 index 0000000000000000000000000000000000000000..df0fa83150087e136811743c6c604d59f59bb8b0 GIT binary patch literal 262 zcmWG=boOpzU|?tf;*gBYVg(>dR47TUC{aku%t__t@+?uvNGw*!P0XuQ$jQu0Emp`+ z1IvS@z^XG6GqXz(n!#M6G{UV(%g;$kEi%*xS!t+OQc(hQ4KaWRsK^$GLHdkH&<8Wy H6RIBo5{ETD literal 0 HcmV?d00001 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..aab6171 --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/stevenhowes/PakExamples + +go 1.17 + +replace github.com/stevenhowes/PakGo => ./PakGo + +require ( + github.com/gorilla/mux v1.8.0 + github.com/stevenhowes/PakGo v0.0.0-00010101000000-000000000000 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..5350288 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= +github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= diff --git a/main.go b/main.go new file mode 100644 index 0000000..0a471c1 --- /dev/null +++ b/main.go @@ -0,0 +1,61 @@ +package main + +import ( + "fmt" + "net/http" + + "github.com/gorilla/mux" + "github.com/stevenhowes/PakGo" +) + +var pak PakGo.PakFile + +func thing(w http.ResponseWriter, req *http.Request) { + out, err := pak.ReadFile(req.URL.String()[1:]) + if err != nil { + w.WriteHeader(http.StatusNotFound) + w.Write([]byte("404 page not found")) + } else { + w.Write(out) + } +} + +func main() { + + pak0, err := PakGo.PakLoad("example.pak") + if err != nil { + panic(err) + } + defer pak0.PakClose() + + pak = pak0 + + fmt.Println("--------") + + out, err := pak0.ReadFile("folder1/file1.txt") + if err != nil { + panic(err) + } + fmt.Println(string(out)) + + fmt.Println("--------") + + out, err = pak0.ReadFile("file2.txt") + if err != nil { + panic(err) + } + fmt.Println(string(out)) + + fmt.Println("--------") + + rtr := mux.NewRouter() + rtr.HandleFunc("/file2.txt", thing).Methods("GET") + rtr.HandleFunc("/folder1/file1.txt", thing).Methods("GET") + rtr.HandleFunc("/invalid.txt", thing).Methods("GET") + + //rtr.PathPrefix("/").Handler(http.FileServer( **TODO: :)** )) + + http.ListenAndServe("127.0.0.1:8881", rtr) + + select {} +}