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 calculator | |
import "context" | |
type operation struct { | |
SavedNumber int | |
} | |
// Add is method implementation to add number with saved number | |
func (s *operation) Add(ctx context.Context, number int) (int, error) { |
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 calculator_test | |
import ( | |
"context" | |
"testing" | |
"github.com/ridhoperdana/calculator" | |
) | |
func TestSempoa_Add(t *testing.T) { |
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 ( | |
"context" | |
"fmt" | |
"github.com/ridhoperdana/calculator" | |
) | |
func main() { |
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
BINARY=crawler | |
# Installing dependency | |
.PHONY: vendor | |
go mod vendor | |
# Linter | |
.PHONY: vendor lint-prepare | |
lint-prepare: | |
@echo "Installing golangci-lint" |
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 models | |
import ( | |
"time" | |
) | |
// Article represent the article model | |
type Article struct { | |
ID int64 `json:"id"` | |
Title string `json:"title" validate:"required"` |
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 Query { | |
FetchArticle(after: String, first: Int): ArticlesResult | |
GetArticleByID(id: Int): Article | |
GetArticleByTitle(title: String): Article | |
} | |
type Mutation { | |
UpdateArticle(id: Int, title: String, content: String): Article | |
StoreArticle(title: String, content: String): Article | |
DeleteArticle(id: 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
type Edge { | |
cursor: String | |
node: Article | |
} | |
type PageInfo { | |
endCursor: String | |
hasNextPage: Boolean | |
} |
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 schema | |
import "github.com/graphql-go/graphql" | |
// Article holds article information with graphql object | |
var Article = graphql.NewObject( | |
graphql.ObjectConfig{ | |
Name: "Article", | |
Fields: graphql.Fields{ | |
"id": &graphql.Field{ |
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 graphql | |
import "github.com/graphql-go/graphql" | |
type Resolver interface { | |
FetchArticle(params graphql.ResolveParams) (interface{}, error) | |
GetArticleByID(params graphql.ResolveParams) (interface{}, error) | |
GetArticleByTitle(params graphql.ResolveParams) (interface{}, error) | |
UpdateArticle(params graphql.ResolveParams) (interface{}, error) |
OlderNewer