Skip to content

Instantly share code, notes, and snippets.

View romanyx's full-sized avatar

Roman Budnikov romanyx

View GitHub Profile
@romanyx
romanyx / ogs_btm_tester.sh
Created October 28, 2019 11:39
Tester output
./ogs_btm_tester.py all
This is a script to perform a simple verification of a wallet platform's integration with OGS BTM.
Wallet URL: http://localhost:8080
Session ID: 3f1b039f-e53a-4c36-a289-0eca51640c6c
Performing test: all
-----------------------
2019-10-28 14:37:41.862413 Testing Ping
REQUEST:
@romanyx
romanyx / usecase.go
Last active December 23, 2018 11:52
Use case
// Service holds data required for registration.
type Service struct {
Validater
Repository
}
// Registrate holds registration domain logic.
func (s *Service) Registrate(ctx context.Context, f *Form) (*User, error) {
if err := s.Validater.Validate(ctx, f); err != nil {
return nil, errors.Wrap(err, "validater validate")
// Registrater abstraction for registration service.
type Registrater interface {
Registrate(*Form) (*User, error)
}
// RegistrationHandler for regisration requests.
type RegistrationHandler struct {
Registrater
}
@romanyx
romanyx / usecase.go
Last active December 23, 2018 11:51
handler with use case
// Repository is a data access layer.
type Repository interface {
Unique(email string) error
Create(*Form) (*User, error)
}
// Validater validation abstraction.
type Validater interface {
Validate(*Form) error
}
@romanyx
romanyx / handler.go
Created December 22, 2018 08:04
Flat handler
// Repository is a data access layer.
type Repository interface {
Exists(email string) (bool, error)
Create(*Form) (*User, error)
}
// RegistrationHandler for handling registration requests.
type RegistrationHandler struct {
Validator *validator.Validate
Repository
@romanyx
romanyx / execute_test.go
Created November 18, 2018 12:42
test driven example
package execute
import (
"bytes"
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
@romanyx
romanyx / execute.go
Last active November 18, 2018 12:41
test driven example
package execute
import (
"errors"
"fmt"
"io"
)
var (
// ErrExpectedError return when error is expected.
@romanyx
romanyx / handler.go
Created November 18, 2018 10:05
net/http
// A Handler responds to an HTTP request.
type Handler interface {
ServeHTTP(ResponseWriter, *Request)
}
// The HandlerFunc type is an adapter to allow the use of
// ordinary functions as HTTP handlers. If f is a function
// with the appropriate signature, HandlerFunc(f) is a
// Handler that calls f.
type HandlerFunc func(ResponseWriter, *Request)
@romanyx
romanyx / example_test.go
Last active June 28, 2018 19:00
example_test.go
package main
import (
"database/sql"
"fmt"
"os"
"testing"
"time"
_ "github.com/go-sql-driver/mysql"
func prepareMySQL(t *testing.T) (db *sql.DB, cleanup func() error) {
db, err := sql.Open("mysql", "test:test@tcp(localhost:3306)/test"))
if err != nil {
t.Fatalf("open mysql connection: %s", err)
}
return db, func() error {
if _, err := db.Exec("TRUNCATE table_name;"); err != nil {
return err