Commit 63ef6633 authored by Richer Maximilien's avatar Richer Maximilien
Browse files

Tweak doc

* Tweak comments
* go-vet cleaning
* Update CI deps config
* Fix unused lib
* Metalinter fixs
parent 8417c9ff
Pipeline #145 failed with stage
......@@ -15,7 +15,7 @@ Unit tests:
- "coverage.html"
script:
- "ln -s $(pwd) $GOPATH/src/dfss"
- "go get gopkg.in/mgo.v2"
- "./build/deps.sh"
- "go test -coverprofile auth.part -v ./auth"
- "go test -coverprofile mgdb.part -v ./mgdb"
- "go test -coverprofile mails.part -v ./mails"
......@@ -28,7 +28,7 @@ ARM tests:
tags:
- arm
script:
- "go get gopkg.in/mgo.v2"
- "./build/deps.sh"
- "go test -cover -short -v ./auth"
- "go test -cover -short -v ./mgdb"
......@@ -41,7 +41,7 @@ Code lint:
script:
- "ln -s $(pwd) $GOPATH/src/dfss"
- "go get github.com/alecthomas/gometalinter"
- "go get gopkg.in/mgo.v2"
- "./build/deps.sh"
- "go install ./..."
- "gometalinter --install"
- "gometalinter -t --deadline=100s -j1 ./..."
#!/bin/sh
# mongo
go get gopkg.in/mgo.v2
# grpc
go get google.golang.org/grpc
......@@ -3,25 +3,22 @@ package net
import (
"crypto/tls"
"crypto/x509"
"flag"
"io/ioutil"
"log"
"math/rand"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/grpclog"
)
// Connect to a peer
// Connect to a peer.
//
// Given parameters cert/key/ca are PEM-encoded array of byte
// Closing must be defered after call
func Connect(addr_port string, cert, key, ca []byte) *ClientConn {
func Connect(addrPort string, cert, key, ca []byte) *grpc.ClientConn {
// load peer cert/key, ca as PEM buffers
peerCert, err := tls.X509KeyPair(cert, key)
if err != nil {
log.Fatal("Load peer cert/key error: %v", err)
log.Fatalf("Load peer cert/key error: %v", err)
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(ca)
......@@ -33,7 +30,7 @@ func Connect(addr_port string, cert, key, ca []byte) *ClientConn {
})
// let's do the dialing !
con, err := grpc.Dial(addr_port, grpc.WithTransportCredentials(ta))
con, err := grpc.Dial(addrPort, grpc.WithTransportCredentials(ta))
if err != nil {
grpclog.Fatalf("Fail to dial: %v", err)
}
......
......@@ -3,31 +3,27 @@ package net
import (
"crypto/tls"
"crypto/x509"
"flag"
"fmt"
"io/ioutil"
"log"
"net"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/grpclog"
)
// Create a new grpc server with given tls creds
// NewServer create a new grpc server with given tls credentials.
//
// cert/key/ca are PEM-encoded array of byte
//
// The returned grpcServer must be used in association with server{} to
// register APIs before calling Listen()
func NewServer(cert, key, ca []byte) *Server {
func NewServer(cert, key, ca []byte) *grpc.Server {
// configure gRPC
var opts []grpc.ServerOption
serverCert, err := tls.X509KeyPair(cert, key)
if err != nil {
log.Fatal("Load peer cert/key error: %v", err)
log.Fatalf("Load peer cert/key error: %v", err)
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(ca)
......@@ -44,16 +40,20 @@ func NewServer(cert, key, ca []byte) *Server {
return grpc.NewServer(opts...)
}
// Listen with specified server on addr:port TCP
// Listen with specified server on addr:port.
//
// addr is the addr to bind to
// port is the port to listen on
func Listen(addr, port string, grpcServer *Server) {
// addrPort is formated as 127.0.0.1:8001
// * addr is the addr to bind to,
// * port is the port to listen on
func Listen(addrPort string, grpcServer *grpc.Server) {
// open tcp socket
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
lis, err := net.Listen("tcp", addrPort)
if err != nil {
grpclog.Fatalf("Failed to open tcp socket: %v", err)
}
grpcServer.Serve(lis)
err = grpcServer.Serve(lis)
if err != nil {
grpclog.Fatalf("Failed to bind gRPC server: %v", err)
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment