Created
June 5, 2017 11:10
-
-
Save bxcodec/89b0a9f67b85bf30e80e301bddb74bd9 to your computer and use it in GitHub Desktop.
Response FlatBuffer
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
package fbs | |
import ( | |
"net/http" | |
"github.com/bxcodec/Go-Simple-Flatbuffer/users" | |
httpdlv "github.com/bxcodec/Go-Simple-Flatbuffer/users/delivery/http" | |
flatbuffers "github.com/google/flatbuffers/go" | |
"github.com/labstack/echo" | |
) | |
type HttpHandlerFbs struct { | |
*UserFbsHandler | |
} | |
func (u *HttpHandlerFbs) Get(c echo.Context) error { | |
b := flatbuffers.NewBuilder(0) | |
buf := u.MakeUser(b, &users.UserObj{int64(64), "Iman"}) | |
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEOctetStream) | |
c.Response().WriteHeader(http.StatusOK) | |
c.Response().Write(buf) | |
c.Response().Flush() | |
return nil | |
} | |
func (u *HttpHandlerFbs) GetListUser(c echo.Context) error { | |
b := flatbuffers.NewBuilder(0) | |
user := &users.UserObj{int64(42), "Iman"} | |
list := make([]*users.UserObj, 0) | |
for i := 0; i < httpdlv.DATA_SIZE; i++ { | |
list = append(list, user) | |
} | |
buf := u.MakeListUser(b, list) | |
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEOctetStream) | |
c.Response().WriteHeader(http.StatusOK) | |
c.Response().Write(buf) | |
c.Response().Flush() | |
return nil | |
} | |
func NewFBSDelivery(e *echo.Echo) { | |
handler := &HttpHandlerFbs{} | |
e.GET("/userfbs", handler.Get) | |
e.GET("/userfbslist", handler.GetListUser) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment