Skip to content

Provide helper functions to setting up gRPC services

License

Notifications You must be signed in to change notification settings

scanoss/go-grpc-helper

Repository files navigation

SCANOSS Platform 2.0 gRPC Helper Package

Welcome to the SCANOSS Platform 2.0 gRPC server helper package.

This package contains helper functions to make development of Go gRPC services easier to configure.

Go Unit Test Golang CI Lint

Repository Structure

This repository is made up of the following components:

Usage

File Manipulation

The files package provides the following helpers:

  • Check if TLS should be enabled or not
  • Load filter config files

TLS

startTLS, err = CheckTLS("server.crt", "server.key")

Filtering

allowedIPs, deniedIPs, err = LoadFiltering("allow_list.txt", "deny_list.txt")

gRPC Server

The server package provides the following helpers:

  • Configure
  • Start
  • Stop

Configure

listen, server, err := SetupGrpcServer(":0", "server.crt", "server.key", allowedIPs, deniedIPs, true, true, false)

Start

StartGrpcServer(listen, server, true)

Stop

err = WaitServerComplete(srv, server)

REST/gRPC Gateway

The gateway package provides the following helpers:

  • Configure
  • Start

Configure

allowedIPs := []string{"127.0.0.1"}
deniedIPs := []string{"192.168.0.1"}
srv, mux, gateway, opts, err := SetupGateway("9443", "8443", "server.crt", allowedIPs, deniedIPs, true, false, true)

Start

StartGateway(srv, "server.crt", "server.key", true)

Database

The database package provide the following helpers:

  • Open DB connection
  • Setup DB options
  • Close DB connection
  • Close SQL connection

Open

db, err := OpenDBConnection(":memory:", "sqlite", "", "", "", "", "")

Setup

err = SetDBOptionsAndPing(db)

Close DB Connection

CloseDBConnection(db)

Close SQL Connection

CloseSQLConnection(conn)

Bugs/Features

To request features or alert about bugs, please do so here.

Changelog

Details of major changes to the library can be found in CHANGELOG.md.