All Projects → ribice → Twisk

ribice / Twisk

Licence: mit
Golang RPC starter kit with Twirp

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Twisk

Gub
CLI tool for create an npm package from any repos. 🐳
Stars: ✭ 31 (-72.57%)
Mutual labels:  starter-kit, starter
React Redux Hooks Starter
React-redux boilerplate using hooks 🎣
Stars: ✭ 69 (-38.94%)
Mutual labels:  starter-kit, starter
Nucleo
🔴 Nucleo - Admin template and Starter project for React
Stars: ✭ 38 (-66.37%)
Mutual labels:  starter-kit, starter
Rpc Thunderdome
A comparison between Proteus RPC and other commonly used RPC frameworks
Stars: ✭ 22 (-80.53%)
Mutual labels:  rpc, protobuf
Node Typescript Mongodb
node js typescript mongodb express generator yo
Stars: ✭ 96 (-15.04%)
Mutual labels:  rest-api, starter
Wordpress Starter
📦 A starter template for WordPress websites
Stars: ✭ 26 (-76.99%)
Mutual labels:  starter-kit, starter
Kubemq
KubeMQ is Enterprise-grade message broker native for Docker and Kubernetes
Stars: ✭ 58 (-48.67%)
Mutual labels:  rest-api, rpc
Brpc Java
Java implementation for Baidu RPC, multi-protocol & high performance RPC.
Stars: ✭ 647 (+472.57%)
Mutual labels:  rpc, protobuf
Angular Webpack Starter
🌟 Angular Webpack Starter with AoT compilation, Lazy-loading, Tree-shaking, and Hot Module Reload (Updated to 4.1.0!)
Stars: ✭ 91 (-19.47%)
Mutual labels:  starter-kit, starter
React Webpack Babel
Simple React Webpack Babel Starter Kit
Stars: ✭ 1,241 (+998.23%)
Mutual labels:  starter-kit, starter
Node Express Boilerplate
A boilerplate for building production-ready RESTful APIs using Node.js, Express, and Mongoose
Stars: ✭ 890 (+687.61%)
Mutual labels:  rest-api, starter
Schema Registry
Confluent Schema Registry for Kafka
Stars: ✭ 1,647 (+1357.52%)
Mutual labels:  rest-api, protobuf
Laravel Boilerplate
Laravel Boilerplate / Starter Kit with Gentelella Admin Theme
Stars: ✭ 704 (+523.01%)
Mutual labels:  starter-kit, starter
Grpc
An Elixir implementation of gRPC
Stars: ✭ 858 (+659.29%)
Mutual labels:  rpc, protobuf
Webpack Simple Starter
A simple webpack starter without framework (Like Vue, React, Angular, etc.)
Stars: ✭ 661 (+484.96%)
Mutual labels:  starter-kit, starter
Niklick
Rails Versioned API solution template for hipsters! (Ruby, Ruby on Rails, REST API, GraphQL, Docker, RSpec, Devise, Postgress DB)
Stars: ✭ 39 (-65.49%)
Mutual labels:  starter-kit, starter
Webpack Starter Basic
A simple webpack starter project for your basic modern web development needs.
Stars: ✭ 552 (+388.5%)
Mutual labels:  starter-kit, starter
Nth Start Project
Startkit for HTML / CSS / JS pages layout.
Stars: ✭ 578 (+411.5%)
Mutual labels:  starter-kit, starter
Easyrpc
EasyRpc is a simple, high-performance, easy-to-use RPC framework based on Netty, ZooKeeper and ProtoStuff.
Stars: ✭ 79 (-30.09%)
Mutual labels:  rpc, protobuf
Protobuf
Protocol Buffers - Google's data interchange format
Stars: ✭ 52,305 (+46187.61%)
Mutual labels:  rpc, protobuf

Twisk - Golang RPC starter kit

Build Status codecov Go Report Card

Twisk is a starter kit for Twirp - a framework for service-to-service communication emphasizing simplicity and minimalism.

It contains things you need to kickstart your project - structured packaging, logging, autogenerated swagger docs, handlers for login/refresh and user CRUD.

I made this project as a preparation for Gophercon 2018 Lightning Talk - Building robust APIs with Twirp.

Read more about Twirp on the official repo, release blog post and documentation website.

Twisk currently has:

  • Fully featured RESTful endpoints for authentication and CRUD operations on the user entity
  • Session handling using JWT claims
  • JWT Based authentication
  • Application configuration via config file (yaml)
  • RBAC (role-based access control)
  • Structured logging
  • Request marshaling and data validation
  • Autogenerated API Docs using SwaggerUI
  • Mocking using stdlib
  • Basic test coverage

The following dependencies are used in this project (generated using Glice):

|---------------------------------------|-----------------------------------------------|-------------|
|             DEPENDENCY                |                    REPOURL                    |   LICENSE   |
|---------------------------------------|-----------------------------------------------|-------------|
| github.com/golang/protobuf            | https://github.com/golang/protobuf            | bsd-3-clause|
| gopkg.in/yaml.v2                      | https://github.com/go-yaml/yaml               | Apache-2.0  |
| github.com/mwitkow/go-proto-validators| https://github.com/mwitkow/go-proto-validators| Apache-2.0  |
| github.com/twitchtv/twirp             | https://github.com/twitchtv/twirp             | Other       |
| github.com/gorilla/mux                | https://github.com/gorilla/mux                | bsd-3-clause|
| github.com/justinas/alice             | https://github.com/justinas/alice             | MIT         |
| github.com/go-pg/pg                   | https://github.com/go-pg/pg                   | bsd-2-clause|
| github.com/rs/xid                     | https://github.com/rs/xid                     | MIT         |
| github.com/nbutton23/zxcvbn-go        | https://github.com/nbutton23/zxcvbn-go        | MIT         |
| github.com/rakyll/statik              | https://github.com/rakyll/statik              | Apache-2.0  |
| github.com/dgrijalva/jwt-go           | https://github.com/dgrijalva/jwt-go           | MIT         |
| github.com/rs/zerolog                 | https://github.com/rs/zerolog                 | MIT         |
|---------------------------------------|-----------------------------------------------|-------------|
  1. Protobuf - Proto formats (timestamp)
  2. Yaml - Unmarshalling YAML config file
  3. Twirp - RPC Framework
  4. Mux - Router
  5. Alice - Chaining middlewares
  6. PG - PostgreSQL ORM
  7. Statik - Static files to binary generator
  8. JWT-GO - JWT Authentication
  9. Zerolog - Logging
  10. XID - Refresh token generation
  11. ZXCVBN-Go - Password strength checker

Most of these can easily be replaced with your own choices since their usage is abstracted and localized. In addition to these, the following tools were used:

  • Retool - Go executables vendoring
  • GoValidators - Proto (request/response) validation
  • TwirpSwagger - Swagger docs generator from proto definitions

Project Structure

Twisk's project structure mostly follows THIS example repository.

Twisk doesn't follow all best practices advices by Twirp. For example, functions are named List, Create and Delete instead of ListUsers, CreateUser and DeleteUser (I prefer shorter function names, handlers and functions named user.List istead of user.ListUsers). You can read on Twirp's best practices here.

Getting started

Using Twisk requires having Go 1.7 or above. Once you downloaded Twisk (either using Git or go get) you need to configure the following:

  1. To use Twisk as a starting point of a real project whose package name is something like github.com/author/project, move the directory $GOPATH/github.com/ribice/twisk to $GOPATH/github.com/author/project and do a global replacement of the string github.com/ribice/twisk with github.com/author/project.

  2. Change the configuration file according to your needs. The local config file is found in cmd/api/conf.local.yaml. You'll need to configure database/psn at least.

  3. In cmd/migration/main.go set up psn variable and then run it (go run main.go). It will create all tables, and necessary data, with a new account username/password admin/admin.

  4. Run the app using:

go run cmd/api/main.go

The application runs as an HTTP server at port 8080. It exposes the following endpoints:

  • GET /openapi/swaggerui: returns list of swagger specs in browser
  • POST /twirp/twisk.iam.IAM/Auth: accepts username or email and password. Returns jwt token and refresh token
  • POST /twirp/twisk.iam.IAM/Refresh: refreshes sessions and returns new jwt token
  • POST /twirp/twisk.user.User/Create: creates a new user
  • POST /twirp/twisk.user.User/List: returns list of users
  • POST /twirp/twisk.user.User/View: returns single user
  • POST /twirp/twisk.user.User/Delete: deletes a user
  • POST /twirp/twisk.user.User/Update: updates user's contact info

You can log in as admin to the application by sending a post request to localhost:8080/twirp/twisk.iam.IAM/Auth with auth admin and password admin in JSON body.

Implementing new APIs

  1. Under proto folder, create a new one named after your service. For example tenant. Inside it create service.proto

  2. Define your proto file. If you are not familiar with Protobufs, you can read more about it here. You can use already existing proto files (proto/user/service.proto & proto/iam/service.proto) as a template.

  3. Run make twirp -B.

  4. Implement the Tenant interface from service.twirp.go in internal/tenant.

  5. Tenant service integrations are located in internal/tenant/platform. For example cloud storage, database, message queue etc.

  6. Implement the interface in logging.go, wrapping around the service implementation.

  7. Add service link to openapi/swagger.html. Alternatively, use build-links in your CI/CD pipeline to auto-generate the swagger.html from swagger.html.template.

  8. Wire up everything in cmd/api/main.go. If neeeded, you can easily skip auth checking on certain routes by passing the service name to hooks.WithJWTAuth(). For example hooks.WithJWTAuth(j, "View","List").

License

Twisk is licensed under the MIT license. Check the LICENSE file for details.

Honorable mention

Special thanks to @tonto for previously creating some parts of this project.

Author

Emir Ribic

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].