Skip to content

Latest commit

 

History

History
82 lines (66 loc) · 1.61 KB

interface.md

File metadata and controls

82 lines (66 loc) · 1.61 KB

Golang Interface

Hexagonal Architecture

Make sure we devide our software in such a way that each peice of the software maintain its separation of concerns by doing this make it extreamly modular.

  1. App and domain logic in the middle
  2. Ports & Adapters
  3. User interface
  4. Repo
  5. External API
  6. Message Queue
  7. REST | GraphQL

Decoupling

package main

import (
	"fmt"
)

type reader interface {
	read() (int, error)
}

type file struct {
	name        string
	fileContent string
}

func (f *file) read() (int, error) 
	content := "file contents"
	f.fileContent = content
	return len(content), nil
}

type pipe struct {
	name        string
	pipeMessage string
}

func (p *pipe) read() (int, error) {
	msg := `{name: "Henry", title: "developer"}`
	p.pipeMessage = msg
	return len(msg), nil
}

func main() {
	f := file{
		name: "data.json",
	}
	p := pipe{
		name: "pipe_message",
	}

	retrieve(&f)
	fmt.Println(f.fileContent)
	retrieve(&p)
	fmt.Println(p.pipeMessage)
}

func retrieve(r reader) error {
	len, _ := r.read()
	fmt.Println(fmt.Sprintf("read %d bytes", len))
	return nil
}

Package used in this project

  • github.com/teris-io/shortid
  • github.com/vmihailenco/msgpack
  • gopkg.in/dealancer/validate.v2

Resource