This repository has been archived by the owner on May 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
120 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
*.o | ||
*.a | ||
*.so | ||
archai | ||
|
||
# Folders | ||
_obj | ||
|
@@ -23,4 +24,4 @@ _testmain.go | |
*.test | ||
*.prof | ||
|
||
vendor | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
run: archai | ||
./archai | ||
|
||
|
||
archai: $(shell find . -type f -regex .*go$) | ||
go build . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package http | ||
|
||
import ( | ||
"gopkg.in/kataras/iris.v6" | ||
) | ||
|
||
type IrisHttpContext struct { | ||
*iris.Context | ||
context Context | ||
} | ||
|
||
func (hc IrisHttpContext) SendJson(response interface{}) { | ||
hc.JSON(iris.StatusOK, response) | ||
} | ||
|
||
func (hc IrisHttpContext) ServerErr(err error) { | ||
hc.context.HandleErr(err) | ||
hc.JSON(iris.StatusInternalServerError, iris.Map{"error": err}) | ||
} | ||
|
||
func (hc IrisHttpContext) GetSegment(index string) string { | ||
return hc.Param(index) | ||
} | ||
|
||
type IrisGetContext struct { | ||
IrisHttpContext | ||
} | ||
|
||
func (hc IrisHttpContext) StringParam(index string) string { | ||
return hc.Param(index) | ||
} | ||
|
||
func (hc IrisHttpContext) IntParam(index string, def int) int { | ||
val, err := hc.ParamInt(index) | ||
if err != nil { | ||
return def | ||
} | ||
|
||
return val | ||
} | ||
|
||
type IrisPostContext struct { | ||
IrisHttpContext | ||
} | ||
|
||
func (hc IrisPostContext) JsonBodyParams() (map[string]interface{}, error) { | ||
sess := iris.Map{} | ||
err := hc.ReadJSON(&sess) | ||
|
||
if err != nil { | ||
hc.JSON(iris.StatusBadRequest, iris.Map{"error": "expected JSON body"}) | ||
} | ||
return sess, err | ||
} | ||
|
||
type IrisHandler struct { | ||
framework *iris.Framework | ||
context Context | ||
} | ||
|
||
func (h *IrisHandler) Get(path string, handler func(GetContext)) { | ||
h.framework.Get(path, func(ctx *iris.Context) { | ||
handler(IrisGetContext{IrisHttpContext{ctx, h.context}}) | ||
}) | ||
} | ||
|
||
func (h *IrisHandler) Post(path string, handler func(PostContext)) { | ||
h.framework.Post(path, func(ctx *iris.Context) { | ||
handler(IrisPostContext{IrisHttpContext{ctx, h.context}}) | ||
}) | ||
} | ||
|
||
func (h *IrisHandler) Run(addr string) error { | ||
h.framework.Listen(addr) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package http | ||
|
||
import ( | ||
"gopkg.in/kataras/iris.v6" | ||
"gopkg.in/kataras/iris.v6/adaptors/httprouter" | ||
) | ||
|
||
func NewIris(c Context) *IrisHandler { | ||
handler := IrisHandler{} | ||
handler.context = c | ||
|
||
app := iris.New() | ||
app.Adapt( | ||
// adapt a logger which prints all errors to the os.Stdout | ||
iris.DevLogger(), | ||
// adapt the adaptors/httprouter or adaptors/gorillamux | ||
httprouter.New(), | ||
) | ||
|
||
handler.framework = app | ||
return &handler | ||
} | ||
|
||
func NewFastHttp(c Context) *FastHttpHandler { | ||
return &FastHttpHandler{Context: c} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.