Skip to content

Commit

Permalink
golang backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Anish2 committed Jan 21, 2017
0 parents commit d4bc9af
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 0 deletions.
Binary file added ComplimentEngine
Binary file not shown.
3 changes: 3 additions & 0 deletions conf/app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
appname = ComplimentEngine
httpport = 8080
runmode = dev
39 changes: 39 additions & 0 deletions controllers/default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package controllers

import (
"fmt"

"github.com/astaxie/beego"
clarifai "github.com/clarifai/clarifai-go"
)

type MainController struct {
beego.Controller
}

type Response2 struct {
Page int `json:"page"`
Fruits []string `json:"fruits"`
}

func (c *MainController) Get() {
client := clarifai.NewClient("ixACIQvGqKKcJCGLT_xnEh4_jlG7dRKXuzF4jam3", "-XQ5gLtB0ZljTUEmoaqV4LI8UXdlwZNEvLTkSXt-")

// Let's get some context about these images
urls := []string{"https://avatars1.githubusercontent.com/u/3252741?v=3&s=400"}
// Give it to Clarifai to run their magic
tag_data, err := client.Tag(clarifai.TagRequest{URLs: urls})

if err != nil {
fmt.Println(err)
} else {
fmt.Println(tag_data.Results[0].Result.Tag.Classes[0])
}

tags := tag_data.Results[0].Result.Tag.Classes

for i := 0; i < len(tags); i++ {
c.Ctx.ResponseWriter.Write([]byte(tag_data.Results[0].Result.Tag.Classes[i] + "\n"))

}
}
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
_ "ComplimentEngine/routers"
"github.com/astaxie/beego"
)

func main() {
beego.Run()
}

10 changes: 10 additions & 0 deletions routers/router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package routers

import (
"ComplimentEngine/controllers"
"github.com/astaxie/beego"
)

func init() {
beego.Router("/", &controllers.MainController{})
}
39 changes: 39 additions & 0 deletions tests/default_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package test

import (
"net/http"
"net/http/httptest"
"testing"
"runtime"
"path/filepath"
_ "ComplimentEngine/routers"

"github.com/astaxie/beego"
. "github.com/smartystreets/goconvey/convey"
)

func init() {
_, file, _, _ := runtime.Caller(1)
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".." + string(filepath.Separator))))
beego.TestBeegoInit(apppath)
}


// TestBeego is a sample to run an endpoint test
func TestBeego(t *testing.T) {
r, _ := http.NewRequest("GET", "/", nil)
w := httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r)

beego.Trace("testing", "TestBeego", "Code[%d]\n%s", w.Code, w.Body.String())

Convey("Subject: Test Station Endpoint\n", t, func() {
Convey("Status Code Should Be 200", func() {
So(w.Code, ShouldEqual, 200)
})
Convey("The Result Should Not Be Empty", func() {
So(w.Body.Len(), ShouldBeGreaterThan, 0)
})
})
}

93 changes: 93 additions & 0 deletions views/index.tpl

Large diffs are not rendered by default.

0 comments on commit d4bc9af

Please sign in to comment.