Skip to content

kutenglaoshu/fabric-sdk-go

 
 

Repository files navigation

Hyperledger Fabric Client SDK for Go

Build Status Go Report Card GoDoc

This SDK enables Go developers to build solutions that interact with Hyperledger Fabric.

Getting started

Obtain the client SDK packages for Fabric and Fabric CA.

go get -u github.com/hyperledger/fabric-sdk-go

# Optional - populate vendor directory (if needed by your downstream vendoring solution)
# cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/
# make populate

You're good to go, happy coding! Check out the examples for usage demonstrations.

Examples

  • E2E Test and Base Test: Part of the E2E tests included with the Go SDK.
  • CLI: An example CLI for Fabric built with the Go SDK.
  • More examples needed!

Community

  • Discussion is happening in Rocket Chat.
  • Issue tracking is handled in Jira.
  • Active development occurs in the Gerrit repository.

Client SDK

Compatibility

  • fabric v1.0.1 & fabric-ca v1.0.1
    • fabric-sdk-go: master:HEAD
  • fabric v1.0.0 & fabric-ca v1.0.0
    • fabric-sdk-go: master:110bf21bf3ab0a9a084f46d9698e1daeeda68a59

Running the test suite

# In the Fabric SDK Go directory
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/

# Optional - Automatically install Go tools used by test suite
# make depend-install

# Running test suite
make

# Clean test suite run artifacts
make clean

Contributing to the Go SDK

If you want to contribute to the Go SDK, please run the test suite and submit patches to the Gerrit git repostory for review. For general guidelines, please refer to the Fabric project's contribution page.

You need:

  • Go
  • Dep
  • Make
  • Docker
  • Docker Compose
  • Git

Gerrit Git repository

To contribute patches, you will need to clone (or add a remote) from Gerrit with authentication.

Running a portion of the test suite

# In the Fabric SDK Go directory
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/

# Ensure dependencies are installed
make depend

# Running code checks (license, linting, spelling, etc)
make checks

# Running all unit tests
make unit-test

# Running all integration tests
make integration-test

Running package unit tests manually

# In a package directory
go test

Running integration tests manually

You need:

  • A working fabric and fabric-ca set up. It is recommended that you use the docker-compose file provided in test/fixtures. It is also recommended that you use the default .env settings provided in test/fixtures. See steps below.
  • Customized settings in the test/fixtures/config/config_test.yaml in case your Hyperledger Fabric network is not running on localhost or is using different ports.

Testing with Fabric Images at Docker Hub

The test suite defaults to the latest compatible tag of fabric images at Docker Hub. The following commands starts Fabric:

# In the Fabric SDK Go directory
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/

# Clean previous test run artifacts
make clean

# Start fabric
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/
docker-compose up --force-recreate

Running Integration Tests

Fabric should now be running. In a different shell, run integration tests

# In the Fabric SDK integration tests directory
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/integration/
go test

Using default config

Default SDK Go configurations are found in the code under /pkg/config/config.yaml

To override the default in non Dev environment, set the default path in the following environment variable:

FABRIC_SDK_CONFIG_PATH=/path/to/default/config yaml(without specifying the yaml file name)

This path value must be a directory. It must contain a default 'config.yaml' file. Note that this default config is used only if environment configuration yaml file is missing to ensure all environment variables are created regardless of their values.

Testing with Local Build of Fabric (Advanced)

Alternatively you can build and run Fabric on your own box using the following commands:

# Build fabric:
cd $GOPATH/src/github.com/hyperledger/
git clone https://github.com/hyperledger/fabric
cd $GOPATH/src/github.com/hyperledger/fabric/
git checkout v1.0.1
make docker

# Build fabric-ca:
cd $GOPATH/src/github.com/hyperledger/
git clone https://github.com/hyperledger/fabric-ca
cd $GOPATH/src/github.com/hyperledger/fabric-ca/
git checkout v1.0.1
make docker

# Start fabric - latest-env.sh overrides the default docker tags in .env
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/
(source latest-env.sh && docker-compose up --force-recreate)

License

Hyperledger Fabric SDK Go software is licensed under the Apache License Version 2.0.


This document is licensed under a Creative Commons Attribution 4.0 International License.