Skip to content

Instantly share code, notes, and snippets.

View Nydan's full-sized avatar
🐢

Danny Aguswahyudi Nydan

🐢
View GitHub Profile
@Nydan
Nydan / integration_test.go
Last active April 15, 2021 09:06
Test case part for integration testing article
// successLoginTest contains context for the test case. The value of each field is
// initialize on setup test case setp and will be the reference for clean up the data on clean().
type successLoginTest struct {
id int64
email string
pass string
}
// createVerifiedUser creates a user to be tested for login API.
func (s *successLoginTest) createVerifiedUser(e *exampleTestSuite) {
@Nydan
Nydan / integration_test.go
Created April 15, 2021 08:54
Test Suite part for integration testing
// +build it
package it
import (
"database/sql"
"io/ioutil"
"net/http"
"github.com/nydan/integration_test/config"
@Nydan
Nydan / config.go
Last active April 15, 2021 08:51
Code snippet for article: Structuring Integration Testing in Golang
package config
type Config struct {
ConnPsql string
}
// Load loads a configuration files into Config struct
func Load(path string) (Config, error) {
return Config{}, nil
}
@Nydan
Nydan / go1.13-errors.go
Created December 16, 2020 15:07
Go 1.13 errors samples.
package main
import (
"errors"
"fmt"
)
var ErrInput = errors.New("wrong input")
var ErrConfig = errors.New("invalid config")
@Nydan
Nydan / settings.json
Created July 16, 2020 13:18
VsCode setting for golang. Enabling gopls and set vs code to follow keyCode in linux
{
"window.menuBarVisibility": "toggle",
"go.formatTool": "goimports",
"go.useLanguageServer": true,
"window.zoomLevel": 0,
"keyboard.dispatch": "keyCode",
"[go]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
@Nydan
Nydan / interface.go
Created December 30, 2018 04:50
Interface example
package main
// Dog struct
type Dog struct{}
// Speak is receiver method for how the dog speak
func (d *Dog) Speak() string {
return "woof"
}
@Nydan
Nydan / constructor_injection.go
Last active December 30, 2018 04:31
Constructor for dependency injection
import "database/sql"
// Resource is type that being used as an object to receive dependency
type Resource struct {
db *sql.DB
}
// New is constructor function that do the injection to Resource
func New(db *sql.DB) *Resource {
r := &Resource{
@Nydan
Nydan / calling_func.go
Created July 2, 2018 09:50
syntax for calling func that receive func as parameter
package main
import "fmt"
func trace(requestName func() string) func(string) string {
return func(text string) string {
request := requestName()
return fmt.Sprintf("operation: %s, request: %s", request, text)
}
@Nydan
Nydan / gracefull_webserver.go
Last active December 21, 2020 19:19
Golang http server with gracefull exit.
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"syscall"
@Nydan
Nydan / go_dependencies_check
Created May 31, 2018 09:53
Checking non standard dependencies from a certain repo
go list -f '{{.Deps}}' | tr "[" " " | tr "]" " " | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}'