Skip to content
Thang Chung edited this page Nov 24, 2022 · 6 revisions

Golang

Project structure

Others

Trouble shooting

Package

go get -u github.com/ilyakaznacheev/cleanenv

Connect to the app running on the host machine in docker-from-docker feature

From the host machine, Ubuntu 22.04 here, type:

> ifconfig

Then find docker0 IP address in the output, just like

docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
    inet6 fe80::42:6dff:fe39:ba02  prefixlen 64  scopeid 0x20<link>
    ether 02:42:6d:39:ba:02  txqueuelen 0  (Ethernet)
    RX packets 994  bytes 122399 (122.3 KB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 759  bytes 772987 (772.9 KB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Here, we can find 172.17.0.1, then use it for all accesses in docker-from-docker

Generate Protobuf/gRPC

> buf mod update proto
> buf generate

Create .env for the first starting

Create .env at your root with content as

PG_URL=postgres://postgres:P@ssw0rd@<your devcontainer IP>:5432/postgres

Migrations

For example, add migration for counter-api

> migrate create -seq -dir cmd/counter/db/migrations -ext sql init_db

Mermaid C4 model

graph TB
  S[myproject]
  M[email service]
  S -.->|sends emails| M
  A[Anonymous User<br/>Person] -.->|Can register a new organisation| S
  B[System Admin<br/>Person] -.->|Manages organisations and accounts| S
  C[Organisation Admin<br/>Person] -.->|Manages organisation, can do X| S
  classDef person fill:#08427b,color:#fff,stroke:none;
  class A,B,C person;
  classDef currentSystem fill:#1168bd,color:#fff,stroke:none;
  class S currentSystem;
  classDef otherSystem fill:#999999,color:#fff,stroke:none;
  class M otherSystem;