archaeopteryx

package module
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2021 License: MIT Imports: 13 Imported by: 2

README

archaeopteryx

codecov Go Reference

This project is a prototype for microservice on Golang with all required dependencies

How to use

archaeopteryx helps you to create service with gRPC, gRPC proxy for REST API and some editional features from the box. All features can be found in the list

Config

Service has configuration, bases on https://github.com/jinzhu/configor. Your application should reimplement config of server like:

import (
	archaeopteryx_config "github.com/iakrevetkho/archaeopteryx/pkg/config"
)

type Config struct {
	archaeopteryx_config.Config
}
Logger

Service has methods to create logger:

import (
	"github.com/sirupsen/logrus"
	archaeopteryx_config "github.com/iakrevetkho/archaeopteryx/logger"
)

func main(){
    var log *logrus.Entry
    log = logger.CreateLogger("main")
}

All messages will be formatted with component name to make easy search by this name:

Logs example

Service server interface

All custom services should implements interface service_server:

// IServiceServer - interface for services servers for archaeopteryx.
//
// All services should implements this interface
// to make possible archaeopteryx registrate services handlers in server
type IServiceServer interface {
	// RegisterGrpc - HealthServiceServer's method to registrate gRPC service server handlers
	RegisterGrpc(sr grpc.ServiceRegistrar) error
	// RegisterGrpcProxy - HealthServiceServer's method to registrate gRPC proxy service server handlers
	RegisterGrpcProxy(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error
}

Features

Install dependencies

make install

Generate protobuf & docs

make generate

Presequinces

archaeopteryx requires folder for log files. To create it run:

sudo mkdir /var/log/archaeopteryx
sudo chown $USER /var/log/archaeopteryx

Build

Docker

To build docker image use:

make build_docker

Run

Binary

To run server use:

make run
Docker

To run server in docker use:

make run_docker

Test

Unit test

For unit tests use:

make test
Lint

For lint use:

make lint
gRPC

For testing gRPC API use Kreya

Folder kreya contains Kreya project for working with the project.

gRPC gateway
Hello world

To test REST gRPC gateway use command:

curl -X POST -k http://localhost:8090/v1/hello -d '{"name": " hello"}'

As a result you should get response: {"message":" hello world"}

User V1
Add User

To test REST gRPC gateway use command:

curl -X POST -k http://localhost:8090/v1/user -d '{"name":"bobby","password":"ilu"}'

As a result you should get response: {"id":<random id>}

Get User

To test REST gRPC gateway use command:

curl -X GET -k http://localhost:8090/v1/user?id=123

As a result you should get response: {"name":"Bobby", "password":"qwerty"}

User V2
Add User

To test REST gRPC gateway use command:

curl -X POST -k http://localhost:8090/v2/user -d '{"firstName":"bobby","lastName":"twist","password":"ilu"}'

As a result you should get response: {"id":<random id>}

Get User

To test REST gRPC gateway use command:

curl -X GET -k http://localhost:8090/v2/user?id=123

As a result you should get response: {"firstName":"Bobby", "lastName":"Twist", "password":"qwerty"}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	Config *config.Config
	// contains filtered or unexported fields
}

func New

func New(config *config.Config, externalServices []service.IServiceServer) (*Server, error)

func (*Server) Run

func (s *Server) Run() error

Directories

Path Synopsis
pkg
proto
gen/health/v1
Package healthcheck is a reverse proxy.
Package healthcheck is a reverse proxy.

Jump to

Keyboard shortcuts

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