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 / ArticleUsecase.go
Last active January 18, 2018 15:40
Article Clean Arch
package usecase
import (
"github.com/bxcodec/go-clean-arch/article"
)
type ArticleUsecase interface {
Fetch(cursor string, num int64) ([]*article.Article, string, error)
GetByID(id int64) (*article.Article, error)
Update(ar *article.Article) (*article.Article, error)
@bxcodec
bxcodec / ArticleUsecase_test.go
Last active October 10, 2017 15:49
TestArticleUsecase Clean Arch
package usecase_test
import (
"errors"
"strconv"
"testing"
"github.com/bxcodec/faker"
models "github.com/bxcodec/go-clean-arch/article"
"github.com/bxcodec/go-clean-arch/article/repository/mocks"
@bxcodec
bxcodec / main.go
Last active October 10, 2017 15:46
Main File of Clean Arch
package main
import (
"database/sql"
"fmt"
"net/url"
httpDeliver "github.com/bxcodec/go-clean-arch/article/delivery/http"
articleRepo "github.com/bxcodec/go-clean-arch/article/repository/mysql"
articleUcase "github.com/bxcodec/go-clean-arch/article/usecase"
@bxcodec
bxcodec / article.json
Last active June 8, 2017 04:05
Sample Article Obj Json Flatbuffer
{
"ID": 63,
"Title": "Ketampanan On Fire",
"Excerpt": "We will won, whatever happen for us",
"Html": "<h3> Ketampanan On Fire </h3> <br> <p> We will Won, Whatever Happer for us </p>",
"Content": [
{
"Text": "Ketampanan will stand over the world",
"TypeContent": "text"
},
@bxcodec
bxcodec / article.fbs
Last active June 9, 2017 02:25
Article fbs Flatbuffer
namespace articles;
table Image {
url: string ;
mime : string ;
width : int ;
height : int ;
}
@bxcodec
bxcodec / glide.yaml
Created June 11, 2017 03:41
Kurio Sample
import:
- package: github.com/stretchr/testify
version: ^1.1.4
- package: github.com/go-sql-driver/mysql
version: ^1.3.0
- package: github.com/arielizuardi/envase
version: v0.2.1
- package: github.com/docker/docker
version: v17.05.0-ce-rc3
subpackages:
package main
import (
"fmt"
"github.com/bxcodec/faker"
)
type SomeStruct struct {
Int int
@bxcodec
bxcodec / repository_test.go
Last active July 7, 2017 10:03
Repository Test
func TestGetByID(t *testing.T) {
db, mock, err := sqlmock.New()
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
defer db.Close()
rows := sqlmock.NewRows([]string{"id", "title", "content", "updated_at", "created_at"}).
AddRow(1, "title 1", "Content 1", time.Now(), time.Now())
query := "SELECT id,title,content,updated_at, created_at FROM article WHERE ID = \\?"
@bxcodec
bxcodec / delivery_test.go
Created July 7, 2017 10:07
Delivery Test
func TestGetByID(t *testing.T) {
var mockArticle models.Article
err := faker.FakeData(&mockArticle)
assert.NoError(t, err)
mockUCase := new(mocks.ArticleUsecase)
num := int(mockArticle.ID)
mockUCase.On("GetByID", int64(num)).Return(&mockArticle, nil)
@bxcodec
bxcodec / golang-prettyurl.go
Created August 7, 2017 03:35 — forked from techslides/golang-prettyurl.go
Generating Pretty Urls for SEO in GoLang using string and regex packages
type Post struct {
// db tag lets you specify the column name if it differs from the struct field
Id int64 `db:"post_id"`
Created int64
Title string `form:"Title" binding:"required"`
Body string `form:"Body"`
UserId int64 `form:"UserId"`
Url string
}