commit 8d4cc6439abe59d0a11e2006ca39a451975ad376 Author: Eduard Urbach Date: Fri Oct 21 19:31:42 2016 +0900 Go rewrite diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..fb069f89 --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# Folders +_obj +_test + +# Architecture specific extensions/prefixes +*.[568vq] +[568vq].out + +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* + +_testmain.go + +*.exe +*.test +*.prof + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# external packages folder +vendor/ \ No newline at end of file diff --git a/src/Anime.go b/src/Anime.go new file mode 100644 index 00000000..aca49095 --- /dev/null +++ b/src/Anime.go @@ -0,0 +1,15 @@ +package main + +// Anime ... +type Anime struct { + ID int `as:"id"` + Title AnimeTitle `as:"title"` + Description string `as:"description"` +} + +// AnimeTitle ... +type AnimeTitle struct { + Romaji string `as:"romaji"` + English string `as:"english"` + Japanese string `as:"japanese"` +} diff --git a/src/Database.go b/src/Database.go new file mode 100644 index 00000000..f2077c7d --- /dev/null +++ b/src/Database.go @@ -0,0 +1,19 @@ +package main + +import as "github.com/aerospike/aerospike-client-go" + +// Client ... +var client *as.Client + +// InitDatabase ... +func InitDatabase() { + client, _ = as.NewClient("127.0.0.1", 3000) +} + +// GetAnime ... +func GetAnime(id int) *Anime { + key, _ := as.NewKey("arn", "Anime", id) + anime := new(Anime) + client.GetObject(nil, key, anime) + return anime +} diff --git a/src/User.go b/src/User.go new file mode 100644 index 00000000..cdef1028 --- /dev/null +++ b/src/User.go @@ -0,0 +1,6 @@ +package main + +// User ... +type User struct { + ID int +} diff --git a/src/main.go b/src/main.go new file mode 100644 index 00000000..fd5067b2 --- /dev/null +++ b/src/main.go @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "time" + + web "github.com/kataras/iris" +) + +func main() { + InitDatabase() + + web.Get("/", func(ctx *web.Context) { + ctx.Response.Header.Set("Content-Type", "text/html;charset=utf-8") + ctx.Write(ctx.Request.URI().String()) + }) + + web.Get("/anime/:id", func(ctx *web.Context) { + start := time.Now() + id, _ := ctx.ParamInt("id") + anime := GetAnime(id) + + ctx.Write(anime.Title.Romaji + "\n") + ctx.Write(anime.Description) + fmt.Println(time.Since(start)) + }) + + web.Listen(":8082") +}