Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pip-services3-go/pip-services3-rp…
Browse files Browse the repository at this point in the history
…c-go
  • Loading branch information
levichevdmitry committed Dec 9, 2020
2 parents 2486689 + b3e3d33 commit 3067ea9
Show file tree
Hide file tree
Showing 27 changed files with 548 additions and 206 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/vendor
/temp/*
/docker/Dockerfile*
/docker/docker-compose*.yml
/*.ps1
/.github
55 changes: 55 additions & 0 deletions .github/workflows/ci-pip-services3-rpc-go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Pip.Services RPC toolkit in Go

on:
push:
paths:
- '**'
- '!README.md'

jobs:
Default:
runs-on: ubuntu-16.04
if: "!contains(github.event.head_commit.message, '[skip-ci]')"
steps:
- uses: actions/checkout@main

############# Prepare #############

- name: Save build number and component version
id: build_info
run: |
echo "##[set-output name=build_number;]$GITHUB_RUN_NUMBER"
echo "##[set-output name=component_version;]$(jq -r '.version' ./component.json)"
echo "##[set-output name=component_name;]$(jq -r '.name' ./component.json)"
- name: Install powershell
run: |
sudo apt-get update
sudo apt-get install -y wget apt-transport-https
wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install -y powershell
############# Build and test #############

# - name: Build the component
# run: ./build.ps1

- name: Test the component
run: ./test.ps1

############# Release #############

- name: Tag branch with the build number
uses: tvdias/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
tag: "v${{ steps.build_info.outputs.component_version }}-${{ steps.build_info.outputs.build_number }}"

############# Clear #############

- name: Clean temporary build artifacts
if: ${{ always() }}
run: ./clean.ps1

9 changes: 2 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
.DS_Store
/dist
/vendor
/data/configs.test.json
/data/device_configs.json
/docker/id_rsa*
*.exe
*.tmp
/.vscode
go.sum
62 changes: 53 additions & 9 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,61 @@
# <img src="https://github.com/pip-services/pip-services/raw/master/design/Logo.png" alt="Pip.Services Logo" style="max-width:30%"> <br/> RPC components for Golang
# <img src="https://uploads-ssl.webflow.com/5ea5d3315186cf5ec60c3ee4/5edf1c94ce4c859f2b188094_logo.svg" alt="Pip.Services Logo" width="200"> <br/> Remote Procedure Calls Golang

This component library is a part of the [Pip.Services](https://github.com/pip-services/pip-services) project.
It contains the Remote Procedure Calls (RPC).
This module is a part of the [Pip.Services](http://pipservices.org) polyglot microservices toolkit.

Quick Links:
The rpc module provides the synchronous communication using local calls or the HTTP(S) protocol. It contains both server and client side implementations.

* [Downloads](https://github.com/pip-services3-go/pip-services3-rpc-go/blob/master/docs/Downloads.md)
The module contains the following packages:
- [**Auth**](https://godoc.org/github.com/pip-services3-go/pip-services3-rpc-go/auth) - authentication and authorization components
- [**Build**](https://godoc.org/github.com/pip-services3-go/pip-services3-rpc-go/build) - HTTP service factory
- [**Clients**](https://godoc.org/github.com/pip-services3-go/pip-services3-rpc-go/clients) - mechanisms for retrieving connection settings from the microservice’s configuration and providing clients and services with these settings
- [**Connect**](https://godoc.org/github.com/pip-services3-go/pip-services3-rpc-go/connect) - helper module to retrieve connections for HTTP-based services and clients
- [**Services**](https://godoc.org/github.com/pip-services3-go/pip-services3-rpc-go/services) - basic implementation of services for connecting via the HTTP/REST protocol and using the Commandable pattern over HTTP

<a name="links"></a> Quick links:

* [Your first microservice in Node.js](https://www.pipservices.org/docs/quickstart/nodejs)
* [Data Microservice. Step 5](https://www.pipservices.org/docs/tutorials/data-microservice/service)
* [Microservice Facade](https://www.pipservices.org/docs/tutorials/microservice-facade/microservice-facade-main)
* [Client Library. Step 2](https://www.pipservices.org/docs/tutorials/client-lib/direct-client)
* [Client Library. Step 3](https://www.pipservices.org/docs/tutorials/client-lib/http-client)
* [API Reference](https://godoc.org/github.com/pip-services3-go/pip-services3-rpc-go/)
* [Configuration](https://github.com/pip-services3-go/pip-services3-rpc-go/blob/master/docs/Configuration.md)
* [Building and Testing](https://github.com/pip-services3-go/pip-services3-rpc-go/blob/master/docs/Development.md)
* [Contributing](https://github.com/pip-services3-go/pip-services3-rpc-go/blob/master/docs/Development.md#contrib)
* [Change Log](CHANGELOG.md)
* [Get Help](https://www.pipservices.org/community/help)
* [Contribute](https://www.pipservices.org/community/contribute)


## Use

Get the package from the Github repository:
```bash
go get -u github.com/pip-services3-go/pip-services3-rpc-go@latest
```

## Develop

For development you shall install the following prerequisites:
* Golang v1.12+
* Visual Studio Code or another IDE of your choice
* Docker
* Git

Run automated tests:
```bash
go test -v ./test/...
```

Generate API documentation:
```bash
./docgen.ps1
```

Before committing changes run dockerized test as:
```bash
./test.ps1
./clear.ps1
```

## Acknowledgements
## Contacts

The library is created and maintained by **Sergey Seroukhov** and **Levichev Dmitry**.

Expand Down
36 changes: 36 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env pwsh

Set-StrictMode -Version latest
$ErrorActionPreference = "Stop"

# Generate image and container names using the data in the "component.json" file
$component = Get-Content -Path "component.json" | ConvertFrom-Json

# Get buildnumber from github actions
if ($env:GITHUB_RUN_NUMBER -ne $null) {
$component.build = $env:GITHUB_RUN_NUMBER
Set-Content -Path "component.json" -Value $($component | ConvertTo-Json)
}

$buildImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-build"
$container=$component.name

# Remove build files
if (Test-Path "./dist") {
$null = Remove-Item -Recurse -Force -Path "./dist/*"
} else {
$null = New-Item -ItemType Directory -Force -Path "./dist"
}

# Build docker image
docker build -f docker/Dockerfile.build -t $buildImage .

# Create and copy compiled files, then destroy
docker create --name $container $buildImage
docker cp "$($container):/app/run" ./dist/run
docker rm $container

if (!(Test-Path "./dist")) {
Write-Host "dist folder doesn't exist in root dir. Build failed. Watch logs above."
exit 1
}
52 changes: 49 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,53 @@
# RPC components for Pip.Services in Golang Changelog
# <img src="https://uploads-ssl.webflow.com/5ea5d3315186cf5ec60c3ee4/5edf1c94ce4c859f2b188094_logo.svg" alt="Pip.Services Logo" width="200"> <br/> Remote Procedure Calls Golang Changelog

## <a name="1.0.1"></a> 1.0.1 (2020-08-05)
## <a name="1.0.8-1.0.11"></a> 1.0.8-1.0.11 (2020-12-02)

### Features
* Fix response error method in HttpResponseSender

* Added helper methods to RestOperations
* Change RegisterWithAuth methods

### Bug Fixes
* Fix authorizer

## <a name="1.0.7"></a> 1.0.7 (2020-11-20)

### Features

* Added swagger support

## <a name="1.0.5-1.0.6"></a> 1.0.5-1.0.6 (2020-11-13)

### Features

* Added helper methods

## <a name="1.0.3-1.0.4"></a> 1.0.3-1.0.4 (2020-11-12)

### Features

* Added helper methods in RestService

### Bug Fixes
* Fix signature CallCommand in CommandableHttpClient

## <a name="1.0.1-1.0.2"></a> 1.0.1-1.0.2 (2020-08-05)

### Features

* Added error handler in Call method of RestClient

### Bug Fixes
* Fix response error method

## <a name="1.0.0"></a> 1.0.0 (2020-01-28)

Initial public release

### Features

* **build** HTTP service factory
* **clients** mechanisms for retrieving connection settings
* **connect** helper module to retrieve connections services and clients
* **services** basic implementation of services for connecting

24 changes: 24 additions & 0 deletions clean.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env pwsh

# Recreate image names using the data in the "component.json" file
$component = Get-Content -Path "component.json" | ConvertFrom-Json
$buildImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-build"
$docsImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-docs"
$testImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-test"

# Clean up build directories
Get-ChildItem -Path "." -Include "exe" -Recurse | foreach($_) { Remove-Item -Force -Recurse $_.FullName }

# Remove docker images
docker rmi $buildImage --force
docker rmi $docsImage --force
docker rmi $testImage --force
docker image prune --force
docker rmi -f $(docker images -f "dangling=true" -q) # remove build container if build fails

# Remove existed containers
$exitedContainers = docker ps -a | Select-String -Pattern "Exit"
foreach($c in $exitedContainers) { docker rm $c.ToString().Split(" ")[0] }

# Remove unused volumes
docker volume rm -f $(docker volume ls -f "dangling=true")
32 changes: 16 additions & 16 deletions clients/CommandableHttpClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ in body object.
Configuration parameters:
base_route: base route for remote URI
- connection(s):
- discovery_key: (optional) a key to retrieve the connection from connect.idiscovery.html IDiscovery]]
- protocol: connection protocol: http or https
- host: host name or IP address
- port: port number
- uri: resource URI or connection string with all parameters in it
- options:
- retries: number of retries (default: 3)
- connect_timeout: connection timeout in milliseconds (default: 10 sec)
- timeout: invocation timeout in milliseconds (default: 10 sec)
base_route: base route for remote URI
- connection(s):
- discovery_key: (optional) a key to retrieve the connection from connect.idiscovery.html IDiscovery]]
- protocol: connection protocol: http or https
- host: host name or IP address
- port: port number
- uri: resource URI or connection string with all parameters in it
- options:
- retries: number of retries (default: 3)
- connect_timeout: connection timeout in milliseconds (default: 10 sec)
- timeout: invocation timeout in milliseconds (default: 10 sec)
References:
Expand Down Expand Up @@ -72,7 +72,7 @@ type CommandableHttpClient struct {

// NewCommandableHttpClient is creates a new instance of the client.
// Parameters:
// - baseRoute string a base route for remote service.
// - baseRoute string a base route for remote service.
// Returns: *CommandableHttpClient
// pointer on new instance
func NewCommandableHttpClient(baseRoute string) *CommandableHttpClient {
Expand All @@ -86,10 +86,10 @@ func NewCommandableHttpClient(baseRoute string) *CommandableHttpClient {
// The call is made via POST operation and all parameters are sent in body object.
// The complete route to remote method is defined as baseRoute + "/" + name.
// Parameters:
// - prototype reflect.Type type of returned data
// - name string a name of the command to call.
// - correlationId string (optional) transaction id to trace execution through call chain.
// - params cdata.StringValueMap command parameters.
// - prototype reflect.Type type of returned data
// - name string a name of the command to call.
// - correlationId string (optional) transaction id to trace execution through call chain.
// - params cdata.StringValueMap command parameters.
// Returns: result interface{}, err error
// result or error.
func (c *CommandableHttpClient) CallCommand(prototype reflect.Type, name string, correlationId string, params *cdata.AnyValueMap) (result interface{}, err error) {
Expand Down
4 changes: 2 additions & 2 deletions clients/Convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

//ConvertComandResult method helps get correct result from JSON by prototype
//Parameters:
// - comRes interface{} input JSON string
// - prototype reflect.Type output object prototype
// - comRes interface{} input JSON string
// - prototype reflect.Type output object prototype
// Returns: convRes interface{}, err error
func ConvertComandResult(comRes interface{}, prototype reflect.Type) (convRes interface{}, err error) {

Expand Down
23 changes: 11 additions & 12 deletions clients/RestClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ import (
RestClient is abstract client that calls remove endpoints using HTTP/REST protocol.
Configuration parameters:
- base_route: base route for remote URI
- connection(s):
- discovery_key: (optional) a key to retrieve the connection from IDiscovery
- protocol: connection protocol: http or https
- host: host name or IP address
- port: port number
- uri: resource URI or connection string with all parameters in it
- options:
- retries: number of retries (default: 3)
- connectTimeout: connection timeout in milliseconds (default: 10 sec)
- timeout: invocation timeout in milliseconds (default: 10 sec)
- base_route: base route for remote URI
- connection(s):
- discovery_key: (optional) a key to retrieve the connection from IDiscovery
- protocol: connection protocol: http or https
- host: host name or IP address
- port: port number
- uri: resource URI or connection string with all parameters in it
- options:
- retries: number of retries (default: 3)
- connectTimeout: connection timeout in milliseconds (default: 10 sec)
- timeout: invocation timeout in milliseconds (default: 10 sec)
References:
- *:logger:*:*:1.0 (optional) ILogger components to pass log messages
Expand Down Expand Up @@ -73,7 +73,6 @@ See CommandableHttpService
...
*/

type RestClient struct {
defaultConfig cconf.ConfigParams
//The HTTP client.
Expand Down
6 changes: 6 additions & 0 deletions component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "pip-services3-rpc-go",
"registry": "github.com/pip-services3-go",
"version": "3.0.0",
"build": 0
}
18 changes: 9 additions & 9 deletions connect/HttpConnectionResolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ and validate connection parameters before returning them.
Configuration parameters:
- connection:
- discovery_key: (optional) a key to retrieve the connection from IDiscovery
- ... other connection parameters
- connections: alternative to connection
- [connection params 1]: first connection parameters
- ...
- [connection params N]: Nth connection parameters
- ...
- connection:
- discovery_key: (optional) a key to retrieve the connection from IDiscovery
- ... other connection parameters
- connections: alternative to connection
- [connection params 1]: first connection parameters
- ...
- [connection params N]: Nth connection parameters
- ...
References:
Expand Down
Loading

0 comments on commit 3067ea9

Please sign in to comment.