timer_apiserver

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2021 License: BSD-3-Clause

README

⏳ Timer API Server

codecov CircleCI Go Report Card GitHub go.mod Go version of a Go module

Timer API Server is a demo Golang project that implements RESTful APIs and gRPC APIs for Timer.

Major Tech stacks: Golang, Gin, gRPC, MariaDB, GORM, Cobra, Pflag, Viper, Docker, GNU Make

Try It Out!

  1. Check prerequisites
  1. Check out the repository to your local machine and go to the project root directory.

    git clone git@github.com:josephzxy/timer_apiserver.git
    cd timer_apiserver
    
  2. Build & launch with docker-compose

    make docker.compose.up
    
  3. Try out RESTful APIs & gRPC APIs

    # Create a timer named "hello"
    make demo.rest.post.hello
    
    # Display current content in the table
    make demo.db.show
    
    # Get the timer named "hello"
    make demo.rest.get.hello
    # Get all timers
    make demo.rest.get.all
    
    # Update the timer named "hello" to a new name "hello_again"
    make demo.rest.put.hello DEMO_REST_PUT_NAME=hello_again
    
    # Get all pending timers
    # Timers are pending if they are not deleted and not triggered yet
    make demo.grpc.getallpending
    
    # Delete the timer named "hello_again"
    make demo.rest.delete.hello_again
    

Overview

System overview

Timer API Server is a demo Golang project that implements RESTful APIs and gRPC APIs for Timer.

  • Loose-coupling design where high-level pluggable controllers(e.g. REST API Server) share layered low-level resource managing service(e.g. MySQL middleware).
  • Aligned with 12-factor-app methodology with supports for taking configurations from various sources, treating logs as event streams, launching the app as stateless processes, etc.
  • Achieved 95% test coverage on CodeCov and A+ on Go Report Card. Leverages GNU Make to automate trivial tasks. Lints, tests, and builds on each commit with CircleCI. Adapted Angular-style Git commit message and Gitflow workflow.
  • Enabled automated building and serving with Docker Compose.
  • Enabled auto-generation of RESTful API Swagger documentation.

API Doc

  • RESTful API

    View swagger doc as a webpage by

    make swagger
    

    Or check out swagger.yml directly.

  • gRPC API

    Please check out timer.proto.

Dev Doc

See Development Documentation.

Directories

Path Synopsis
api
rest/swagger/docs
Package docs Timer API Server.
Package docs Timer API Server.
apiserver is the API server that provides both external-facing RESTful API and internal-facing gRPC API for managing RESTful resource "Timer".
apiserver is the API server that provides both external-facing RESTful API and internal-facing gRPC API for managing RESTful resource "Timer".
internal
app
Package app is the logical main body of the program.
Package app is the logical main body of the program.
app/cliflags
Package cliflags manages all command line flags for the app.
Package cliflags manages all command line flags for the app.
app/config
Package config manages all app-level configs.
Package config manages all app-level configs.
app/gracefulshutdown
Package gracefulshutdown implements a simple library for enabling app-level graceful shutdown on receiving shutdown OS signals like SIGTERM and SIGINT.
Package gracefulshutdown implements a simple library for enabling app-level graceful shutdown on receiving shutdown OS signals like SIGTERM and SIGINT.
grpcserver
Package grpcserver implements a pluggable library for gRPC servers.
Package grpcserver implements a pluggable library for gRPC servers.
pkg/err
Package err implements a library for the app to handle the representation of errors to end users.
Package err implements a library for the app to handle the representation of errors to end users.
pkg/log
Package log provides a simple encapsulation of the logging library "go.uber.org/zap".
Package log provides a simple encapsulation of the logging library "go.uber.org/zap".
pkg/util
Package util provides utility functions.
Package util provides utility functions.
resource/v1/model
Package model defines data models used in the app
Package model defines data models used in the app
resource/v1/service
Package service is a generated GoMock package.
Package service is a generated GoMock package.
resource/v1/store
Package store provides low-level interfaces for data storage operations.
Package store provides low-level interfaces for data storage operations.
resource/v1/store/mysql
Package mysql provides MySQL-specific implementations of interface store.Router
Package mysql provides MySQL-specific implementations of interface store.Router
resource/v1/store/mysql/timer
Package timer provides an implementation to interface store.TimerStore for MySQL operations of RESTful resource Timer.
Package timer provides an implementation to interface store.TimerStore for MySQL operations of RESTful resource Timer.
restserver
Package restserver implements a pluggable library for REST servers.
Package restserver implements a pluggable library for REST servers.
restserver/controller/v1/timer
Package timer provides an interface of HTTP controller for RESTful resource Timer as well as an implementation.
Package timer provides an interface of HTTP controller for RESTful resource Timer as well as an implementation.
restserver/middleware
Package middleware provides middlewares for REST server.
Package middleware provides middlewares for REST server.
restserver/response
Package response provides a uniformed interface for writing HTTP responses.
Package response provides a uniformed interface for writing HTTP responses.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL