summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolaus Gotsche <n@softwarefools.com>2017-10-02 03:00:34 +0200
committerNikolaus Gotsche <n@softwarefools.com>2017-10-02 03:00:34 +0200
commitb4d150602df5b9a61a3d3b1084524c9317c55cde (patch)
treeff02fad70fb2306cf5486a104b448535294b90b2
parent7a38dbeffad2899a6dab74ec9a491e7e7807ba9b (diff)
iengine.go - Here comes all the Mapcration and Action calculus
adde maps and stuff
-rw-r--r--engine.go8
-rw-r--r--getuuid.go15
-rw-r--r--jsonrest.go96
3 files changed, 8 insertions, 111 deletions
diff --git a/engine.go b/engine.go
new file mode 100644
index 0000000..3186f5f
--- /dev/null
+++ b/engine.go
@@ -0,0 +1,8 @@
+package main
+
+
+func getNewArea(x,y int, nam string) Area {
+ myArea := Area{x,y,0,nam,0,0}
+ return myArea
+
+}
diff --git a/getuuid.go b/getuuid.go
deleted file mode 100644
index b9cb7ae..0000000
--- a/getuuid.go
+++ /dev/null
@@ -1,15 +0,0 @@
-package main
-
-import (
- "fmt"
- "log"
- "os/exec"
-)
-
-func main() {
- out,err := exec.Command("uuidgen").Output()
- if err != nil {
- log.Fatal(err)
- }
- fmt.Printf("%s", out)
-}
diff --git a/jsonrest.go b/jsonrest.go
deleted file mode 100644
index e6e948e..0000000
--- a/jsonrest.go
+++ /dev/null
@@ -1,96 +0,0 @@
-package main
-
-import (
- "net/http"
- "log"
- "sync"
- "github.com/ant0ine/go-json-rest/rest"
-)
-
-func main() {
- api := rest.NewApi()
- api.Use(rest.DefaultDevStack...)
-// api.SetApp(rest.AppSimple(func(w rest.ResponseWriter, r *rest.Request) {
-// w.WriteJson(map[string]string{"Body": "Hello World!"})
-// }))
-// log.Fatal(http.ListenAndServe(":8086", api.MakeHandler()))
- router, err := rest.MakeRouter(
- rest.Get("/countries", GetAllCountries),
- rest.Post("/countries", PostCountry),
- rest.Get("/countries/:code", GetCountry),
- rest.Delete("/countries/:code", DeleteCountry),
- )
- if err != nil{
- log.Fatal(err)
- }
- api.SetApp(router)
- log.Fatal(http.ListenAndServe(":8086", api.MakeHandler()))
-}
-
-type Country struct {
- Code string
- Name string
-}
-
-var store = map[string]*Country{}
-
-var lock = sync.RWMutex{}
-
-func GetCountry(w rest.ResponseWriter, r *rest.Request) {
- code := r.PathParam("code")
-
- lock.RLock()
- var country *Country
- if store[code] != nil {
- country = &Country{}
- *country = *store[code]
- }
- lock.RUnlock()
- if country == nil {
- rest.NotFound(w, r)
- return
- }
- w.WriteJson(country)
-
-}
-
-func GetAllCountries(w rest.ResponseWriter, r *rest.Request) {
- lock.RLock()
- countries := make([]Country, len(store))
- i := 0
- for _, country := range store {
- countries[i] = *country
- i++
- }
- lock.RUnlock()
- w.WriteJson(&countries)
-}
-
-func PostCountry(w rest.ResponseWriter, r *rest.Request) {
- country := Country{}
- err := r.DecodeJsonPayload(&country)
- if err != nil {
- rest.Error(w, err.Error(), http.StatusInternalServerError)
- return
- }
- if country.Code == "" {
- rest.Error(w, "country code required", 400)
- return
- }
- if country.Name == "" {
- rest.Error(w, "country name required", 400)
- return
- }
- lock.Lock()
- store[country.Code] = &country
- lock.Unlock()
- w.WriteJson(&country)
-}
-
-func DeleteCountry(w rest.ResponseWriter, r *rest.Request) {
- code := r.PathParam("code")
- lock.Lock()
- delete(store, code)
- lock.Unlock()
- w.WriteHeader(http.StatusOK)
-}