templecloud / go-commit-log

Distributed Services with Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-commit-log

A simple commit log example for distributed computing.

See: Distributed Services with Go


Build

Run Server

go run cmd/server/main.go

Add Data

$ curl -X POST localhost:8080 -d \
'{"record": {"value": "TGV0J3MgR28gIzEK"}}'
$ curl -X POST localhost:8080 -d \
'{"record": {"value": "TGV0J3MgR28gIzIK"}}'
$ curl -X POST localhost:8080 -d \
'{"record": {"value": "TGV0J3MgR28gIzMK"}}'

Read Data

$ curl -X GET localhost:8080 -d '{"offset": 0}'
$ curl -X GET localhost:8080 -d '{"offset": 1}'
$ curl -X GET localhost:8080 -d '{"offset": 2}'

Protobuf

  1. Download the latest version of protoc for the target system.

    sudo apt install protobuf-compiler
    sudo apt install golang-goprotobuf-dev
  2. Add proto files

    mkdir -p api/v1
    touch api/v1/log.protot
  3. Install protobuf into project

    go get google.golang.org/protobuf/...@v1.25.0
  4. Generate

    protoc api/v1/*.proto \
        --go_out=. \
        --go_opt=paths=source_relative \
        --proto_path=.

About

Distributed Services with Go


Languages

Language:Go 96.2%Language:Makefile 3.8%