herots

package module
v2.1.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2015 License: BSD-2-Clause Imports: 9 Imported by: 1

README

HEROTS

Go (golang) package for simple and fast creation of TLS-servers and/or TLS-clients.

go get -u github.com/iu0v1/herots

For more infomation, please look at the examples and read the doc.

Outputs from examle server and client:

$ go run example/server/server.go

herots: load key pair - ok
herots: listening on localhost:9001
herots: accepted conn from 127.0.0.1:64163
2015/07/22 04:08:02 from client: Hello server! Message 1
2015/07/22 04:08:02 to client: Hello server! Message 1
2015/07/22 04:08:02 from client: Hello server! Message 2
2015/07/22 04:08:02 to client: Hello server! Message 2
2015/07/22 04:08:02 from client: Hello server! Message 3
2015/07/22 04:08:02 to client: Hello server! Message 3
2015/07/22 04:08:02 from client: 127.0.0.1:64163 send EOF


$ go run example/client/client.go

herots: load key pair - ok
herots: add cert to root CA - ok
herots: dial to localhost:9001 - ok
2015/07/22 04:08:02 client: wrote "Hello server! Message 1" (23 bytes)
2015/07/22 04:08:02 client: read "Hello server! Message 1" (23 bytes)
2015/07/22 04:08:02 client: wrote "Hello server! Message 2" (23 bytes)
2015/07/22 04:08:02 client: read "Hello server! Message 2" (23 bytes)
2015/07/22 04:08:02 client: wrote "Hello server! Message 3" (23 bytes)
2015/07/22 04:08:02 client: read "Hello server! Message 3" (23 bytes)
2015/07/22 04:08:02 client: exiting

Have a nice day :)

Documentation

Overview

Package herots provide fast way to create TLS services: server and client.

Explanation of the name: HERald Of The Swarm

By the way - have a nice day :)

Index

Constants

View Source
const (
	LoadKeyPairError   = "load key pair error"
	NoKeyPairLoadError = "no load key pair (use LoadKeyPair func)"
)

predefined errors messages

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client - primary struct for client implementation.

func NewClient

func NewClient(o *Options) *Client

NewClient - function for create Client struct

func (*Client) AddCertToRootCA

func (c *Client) AddCertToRootCA(cert []byte) error

AddCertToRootCA - function to load additional certificates to root CA pool.

func (*Client) Dial

func (c *Client) Dial() (*tls.Conn, error)

Dial - function for start connection with server.

func (*Client) LoadKeyPair

func (c *Client) LoadKeyPair(cert, key []byte) error

LoadKeyPair - function for load certificate and private key pair.

Public/private key pair require as PEM encoded data.

type LogHandlerFunc

type LogHandlerFunc func(message string, lvl LogLevelType)

LogHandlerFunc - type for log handler functions

type LogLevelType

type LogLevelType int

LogLevelType - declare the level of informatyvity of log message

const (
	LogLevelNone LogLevelType = iota
	LogLevelNotice
	LogLevelInfo
	LogLevelError
)

predefined LogLevelType levels

type Options

type Options struct {
	// Server host.
	//
	// Default: '127.0.0.1'.
	Host string

	// Server port.
	//
	// Default: '9000'.
	Port int

	// LogLevel provides the opportunity to choose the level of
	// information messages.
	// Each level includes the messages from the previous level.
	// LogLevelNone   - no messages // 0
	// LogLevelNotice - notice      // 1
	// LogLevelInfo   - info        // 2
	// LogLevelError  - error       // 3
	//
	// Default: LogLevelNone.
	LogLevel LogLevelType

	// LogDestination provides the opportunity to choose the own
	// destination for log messages (errors, info, etc).
	//
	// Default: 'os.Stdout'.
	LogDestination io.Writer

	// LogHandler takes log messages to bypass the internal
	// mechanism of the message processing
	//
	// If LogHandler is selected - all log settings will be ignored.
	LogHandler LogHandlerFunc

	// TLSAuthType - refer to http://golang.org/pkg/crypto/tls/#ClientAuthType
	//
	// This option ignored for client implementation.
	//
	// Default: tls.RequireAnyClientCert
	TLSAuthType tls.ClientAuthType
}

Options - structure, which is used to configure a TLS server and client.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server - primary struct for server implementation.

func NewServer

func NewServer(o *Options) *Server

NewServer - function for create Server struct

func (*Server) Accept

func (s *Server) Accept() (net.Conn, error)

Accept - accept and return connections.

func (*Server) AddClientCACert

func (s *Server) AddClientCACert(cert []byte) error

AddClientCACert - function for adding client CA certificate to x509.CertPool (tls.Config.ClientCAs).

By default server add cert from server public/private key pair (LoadKeyPair) to cert pool.

func (*Server) LoadKeyPair

func (s *Server) LoadKeyPair(cert, key []byte) error

LoadKeyPair - function for load certificate and private key pair.

Public/private key pair require as PEM encoded data.

func (*Server) Start

func (s *Server) Start() error

Start - function for start server.

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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