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.
- App and domain logic in the middle
- Ports & Adapters
- User interface
- Repo
- External API
- Message Queue
- REST | GraphQL
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
}
- github.com/teris-io/shortid
- github.com/vmihailenco/msgpack
- gopkg.in/dealancer/validate.v2