Skip to content

Instantly share code, notes, and snippets.

View bxcodec's full-sized avatar
:octocat:
Learning and Making

Iman Tumorang bxcodec

:octocat:
Learning and Making
View GitHub Profile
@bxcodec
bxcodec / usingmath.go
Last active April 12, 2017 07:57
Using math library
package main
import (
"fmt"
"math"
)
func main() {
x := -5
fmt.Println(math.Abs(float64(x))) // print : 5
}
@bxcodec
bxcodec / example.go
Last active April 12, 2017 08:07
Using Saint
package main
import (
"fmt"
"github.com/bxcodec/saint"
)
func main() {
@bxcodec
bxcodec / Container.go
Created June 5, 2017 07:44 — forked from urakozz/Container.go
Flat Buffers with Golang
// automatically generated, do not modify
package encoder
import (
flatbuffers "github.com/google/flatbuffers/go"
)
type Container struct {
_tab flatbuffers.Table
}
@bxcodec
bxcodec / flatbuffers-vector.go
Created June 5, 2017 08:54 — forked from mish15/flatbuffers-vector.go
flatbuffers pack nested vector
func (term *Term) Encode(version string) []byte {
builder := flatbuffers.NewBuilder(0)
// Preprocess the shotguns
shotguns := make([]flatbuffers.UOffsetT, len(term.Shotgun))
shotgunStrs := make([]flatbuffers.UOffsetT, len(term.Shotgun))
for i := 0; i < len(term.Shotgun); i++ {
shotgunStrs[i] = builder.CreateString(term.Shotgun[i].Term)
}
for i := 0; i < len(term.Shotgun); i++ {
@bxcodec
bxcodec / serialize_test.go
Last active June 5, 2017 10:42
Serializing Flatbuffer
package fbs_test
import (
"encoding/json"
"testing"
"github.com/bxcodec/Go-Simple-Flatbuffer/users"
httpdlv "github.com/bxcodec/Go-Simple-Flatbuffer/users/delivery/http"
"github.com/bxcodec/Go-Simple-Flatbuffer/users/delivery/http/fbs"
@bxcodec
bxcodec / rest.go
Created June 5, 2017 11:10
Response FlatBuffer
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"
)
@bxcodec
bxcodec / http_test.go
Created June 5, 2017 11:13
Test Over Network FlatBuffer
package http_test
import (
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
@bxcodec
bxcodec / user.fbs
Created June 5, 2017 11:29
User FlatBuffer
namespace users;
table User {
name : string ;
id : long;
}
table UserContainer {
ListOfUsers:[User];
@bxcodec
bxcodec / Article.go
Created June 6, 2017 08:53
Article Clean Arch
import "time"
type Article struct {
ID int64 `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt time.Time `json:"created_at"`
}
@bxcodec
bxcodec / ArticleRepository.go
Last active October 10, 2017 15:44
ArticleRepo Clean Arch
package repository
import models "github.com/bxcodec/go-clean-arch/article"
type ArticleRepository interface {
Fetch(cursor string, num int64) ([]*models.Article, error)
GetByID(id int64) (*models.Article, error)
GetByTitle(title string) (*models.Article, error)
Update(article *models.Article) (*models.Article, error)
Store(a *models.Article) (int64, error)