Go rewrite

This commit is contained in:
Eduard Urbach 2016-10-21 19:31:42 +09:00
commit 8d4cc6439a
5 changed files with 99 additions and 0 deletions

30
.gitignore vendored Normal file
View File

@ -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/

15
src/Anime.go Normal file
View File

@ -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"`
}

19
src/Database.go Normal file
View File

@ -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
}

6
src/User.go Normal file
View File

@ -0,0 +1,6 @@
package main
// User ...
type User struct {
ID int
}

29
src/main.go Normal file
View File

@ -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")
}