singular

package module
v0.0.0-...-501eabc Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2016 License: MIT Imports: 15 Imported by: 2

README

A simple reverse proxy

Installation

# compile server and client
go get -v github.com/Dreamacro/singulard/cmd/singulard
go get -v github.com/Dreamacro/singular/cmd/singular

Getting started

Server
# run server
singulard -port 8000
Options
  • -port port, e.g., -port 8000, default 8080
  • -log logPath, e.g., -log proxy.log, default log is tty mode
  • -tls, with tls
  • -cert cert, e.g., -cert cert.pem, default cert.pem
  • -key key, e.g., -key cert.key, default cert.key
Client
# run client
singular -config config.yml
Options
  • -config yaml, e.g., -config config.yaml, default config.yml
server_addr: domain.com:8080
proxy:
    ssh: tcp://0.0.0.0:22
    docker: unix:///var/run/docker.sock
  • -log logPath, e.g., -log proxy.log, default log is tty mode
  • -tls, with tls
  • -cert cert, e.g., -cert cert.pem, default cert.pem
  • -key key, e.g., -key cert.key, default cert.key

Start with tls

singulard -tls
singular -tls

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Version request header
	Version = []byte("\x01MAGIC")
)

Functions

func CheckError

func CheckError(msg string, err error)

CheckError print error log

func NewTLSConfig

func NewTLSConfig(certFile, keyFile string) (*tls.Config, error)

NewTLSConfig return tls.config

func PassOrFatal

func PassOrFatal(msg string, err error)

PassOrFatal print error and fatal

Types

type Client

type Client struct {
	Sessions
	Name       string
	LocalAddr  string
	ServerAddr string
	// contains filtered or unexported fields
}

Client define a client

func NewClient

func NewClient(name, localAddr, serverAddr string, tls bool, tlsConfig *tls.Config) *Client

NewClient return a client

func (*Client) Close

func (client *Client) Close()

Close Client

func (*Client) Connect

func (client *Client) Connect() error

Connect connect server

func (*Client) Process

func (client *Client) Process(conn Conn, addr string)

Process working

type Config

type Config struct {
	ServerAddr string            `yaml:"server_addr,omitempty"`
	AuthToken  string            `yaml:"auth_token"`
	Proxy      map[string]string `yaml:"proxy"`
}

Config define a client config

func ParseConfig

func ParseConfig(path string) (config *Config, err error)

ParseConfig parse config file

type Conn

type Conn struct {
	net.Conn
}

Conn define a connect

func NewConn

func NewConn(conn net.Conn) Conn

NewConn return a new Conn

func (*Conn) Receive

func (conn *Conn) Receive() (buf []byte, err error)

Receive conn receive data

func (*Conn) Send

func (conn *Conn) Send(serialized []byte) (err error)

Send conn send data

type Proxy

type Proxy struct {
	Sessions
	Name     string
	Port     int
	Listener net.Listener
	// contains filtered or unexported fields
}

Proxy define a Proxy

func NewProxy

func NewProxy(conn Conn, name string, useTLS bool, tlsConfig *tls.Config) *Proxy

NewProxy create a new proxy

func (*Proxy) Close

func (proxy *Proxy) Close()

Close notification

func (*Proxy) Listen

func (proxy *Proxy) Listen()

Listen proxy listen

type Server

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

Server define a server type

func NewServer

func NewServer(tls bool, tlsConfig *tls.Config) *Server

NewServer generator a new server

func (*Server) Serve

func (server *Server) Serve(port int)

Serve serve a adderss

type Session

type Session struct {
	ID []byte

	CloseC chan []byte
	Done   chan struct{}
	// contains filtered or unexported fields
}

Session define session.

func NewSession

func NewSession(sessionID []byte, conn Conn, out chan []byte, close chan []byte) Session

NewSession return a new session and start a goroutine

func (*Session) Close

func (session *Session) Close()

Close the conn

func (*Session) Send

func (session *Session) Send(buf []byte)

Send data to chan

type Sessions

type Sessions struct {
	Sessions map[string]Session
	Client   Conn
	CloseC   chan []byte
	OutC     chan []byte
	Done     chan struct{}
}

Sessions define sessions.

func NewSessions

func NewSessions(client Conn) Sessions

NewSessions return a sessions

func (*Sessions) Add

func (sessions *Sessions) Add(id []byte, sessionConn Conn) Session

Add session to map

func (*Sessions) Close

func (sessions *Sessions) Close()

Close all sessions and goroutine

func (*Sessions) Delete

func (sessions *Sessions) Delete(id []byte)

Delete session from map

func (*Sessions) Get

func (sessions *Sessions) Get(id []byte) (session Session, ok bool)

Get session from map

Directories

Path Synopsis
cmd
Package singular is a generated protocol buffer package.
Package singular is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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