Giter VIP home page Giter VIP logo

go-distributed-systems's Introduction

Go Distributed Systems

This is a miniature, Go-based distributed system that supports the microservices architecture. It provides features such as service registration, discovery, dependency updates, and a basic load balancing mechanism. You can integrate your own microservice by adding it to the cmd directory. This distributed system combines elements of both the hub-and-spoke model and the peer-to-peer model.

Prerequisites

Go v1.21 or higher

Docker

Getting Started

Start the micro services with Docker

docker-compose up

Using Package Service API Endpoints

Use the API endpoints provided by the package service to create your own microservice.

For example, to register a service with the registry:

host, port := "yourservicename", "4000"
serviceAddr := fmt.Sprintf("http://%s:%s", host, port)
r := registry.Registration{
	ServiceName:      registry.LogService,
	ServiceURL:       serviceAddr,
	RequiredServices: make([]registry.ServiceName, 0),
	ServiceUpdateURL: serviceAddr + "/services",
	HeartbeatURL:     serviceAddr + "/heartbeat",
}
ctx, err := service.Start(
	context.Background(),
	host,
	port,
	r,
	log.RegisterHandlers,
)

Afterward, create the corresponding Dockerfile and docker-compose.yml files for the microservice, using formats similar to the ones presented here:

Dockerfile.yourservicename

FROM golang:1.21 AS builder

WORKDIR /app

COPY go.mod ./

RUN go mod download

COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o yourservicename ./cmd/yourservicename

FROM alpine:latest  

RUN apk --no-cache add ca-certificates

WORKDIR /root/

COPY --from=builder /app/yourservicename .

EXPOSE portnumber

CMD ["./yourservicename"]

docker-compose.yml

  yourservicename:
    build:
      context: .
      dockerfile: Dockerfile.yourservicename
    ports:
      - "portnumber:portnumber"
    stdin_open: true
    tty: true
    depends_on:
      - registryservice
      - logservice
      - ...

go-distributed-systems's People

Contributors

gavinnwang avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.