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
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 | |
} |
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
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) |
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
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 = \\?" |
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 main | |
import ( | |
"fmt" | |
"github.com/bxcodec/faker" | |
) | |
type SomeStruct struct { | |
Int int |
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
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: |
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
namespace articles; | |
table Image { | |
url: string ; | |
mime : string ; | |
width : int ; | |
height : int ; | |
} | |
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
{ | |
"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" | |
}, |
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 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" |
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 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" |
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 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) |