frontender

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2017 License: Apache-2.0 Imports: 22 Imported by: 1

README

frontender

Setup a server frontend with HTTPS that then proxies to traffic to a backend/cluster.

This project is used inside orijtech to create for folks HTTPS servers that can then be put in Docker images, or automatically uploaded to respective cloud storage systems and passed into some container engine for a disk image.

Examples:

  • Preamble with imports:
package frontender_test

import (
	"io"
	"log"
	"os"

	"github.com/orijtech/frontender"
)
  • Plain listen as a server:
func listen() {
	lc, err := frontender.Listen(&frontender.Request{
		Domains: []string{
			"git.orijtech.com",
			"repo.orijtech.com",
		},
		NonHTTPSRedirectURL: "https://git.orijtech.com",

		ProxyAddress: "http://localhost:9845",

		NoAutoWWW: true,
	})
	if err != nil {
		log.Fatal(err)
	}
	defer lc.Close()

	if err := lc.Wait(); err != nil {
		log.Fatal(err)
	}
}
  • Generate the binary of the server for a platform
func generateBinary() {
	rc, err := frontender.GenerateBinary(&frontender.DeployInfo{
		FrontendConfig: &frontender.Request{
			Domains: []string{
				"www.medisa.orijtech.com",
				"medisa.orijtech.com",
				"m.orijtech.com",
			},
			ProxyAddress: "http://192.168.1.105:9855",
		},
		TargetGOOS: "linux",
		Environ:    []string{"CGO_ENABLED=0"},
	})
	if err != nil {
		log.Fatal(err)
	}
	defer rc.Close()

	f, err := os.Create("theBinary")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	io.Copy(f, rc)
}
  • Generate a Docker image for the server
func generateDockerImage() {
	imageName, err := frontender.GenerateDockerImage(&frontender.DeployInfo{
		CanonicalImageNamePrefix: "frontender",
		FrontendConfig: &frontender.Request{
			Domains: []string{
				"git.orijtech.com",
				"repo.orijtech.com",
			},
			NonHTTPSRedirectURL: "https://git.orijtech.com",

			ProxyAddress: "http://localhost:9845",

			NoAutoWWW: true,
		},
		ImageName: "odex-auto",
	})
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("ImageName: %q\n", imageName)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateBinary

func GenerateBinary(req *DeployInfo) (io.ReadCloser, error)

func GenerateDockerImage

func GenerateDockerImage(req *DeployInfo) (imageName string, err error)

func GenerateDockerImageForGCE

func GenerateDockerImageForGCE(req *DeployInfo) (imageName string, err error)

Types

type BinaryHandle

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

func (*BinaryHandle) Close

func (bh *BinaryHandle) Close() error

func (*BinaryHandle) Read

func (bh *BinaryHandle) Read(b []byte) (int, error)

type Dependency

type Dependency struct {
	LocalPath  string
	DockerPath string
}

type DeployInfo

type DeployInfo struct {
	FrontendConfig *Request
	SourceImage    string
	ImageName      string

	TargetGOOS string
	Environ    []string

	CanonicalImageName       string `json:"canonical_image_name"`
	CanonicalImageNamePrefix string `json:"canonical_image_name_prefix"`
}

type DockerConfig

type DockerConfig struct {
	PrerunCommands []string      `json:"prerun_commands"`
	Dependencies   []*Dependency `json:"dependencies"`
	ImageName      string        `json:"image_name"`
	SourceImage    string        `json:"source_image"`
	BinaryPath     string        `json:"binary_path"`
}

type ListenConfirmation

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

func Listen

func Listen(req *Request) (*ListenConfirmation, error)

The goal is to be able to pass in proxy servers, keep a persistent connection to each one of them and use that as the weight to figure out which one to send traffic to.

func (*ListenConfirmation) Close

func (lc *ListenConfirmation) Close() error

func (*ListenConfirmation) Wait

func (lc *ListenConfirmation) Wait() error

type Request

type Request struct {
	// HTTP1 signifies that this server should
	// not be ran as an HTTP/2<-->HTTPS server.
	// This variable is useful for testing purposes.
	HTTP1 bool `json:"http1"`

	Domains []string `json:"domains"`

	NoAutoWWW bool `json:"no_auto_www"`

	ProxyAddresses []string `json:"proxy_addresses"`

	NonHTTPSRedirectURL string `json:"non_https_redirect_url"`
	NonHTTPSAddr        string `json:"non_https_addr"`

	DomainsListener func(domains ...string) net.Listener

	Environ    []string `json:"environ"`
	TargetGOOS string   `json:"target_goos"`

	CertKeyFiler func() (string, string)

	// BackendPingPeriod if set, defines the period
	// between which the frontend service will check
	// for the liveliness of the backends.
	BackendPingPeriod time.Duration
}

func (*Request) SynthesizeDomains

func (req *Request) SynthesizeDomains() []string

Synthesizes domains removing duplicates and if NoAutoWWW if not set, will automatically make the corresponding www.domain domain.

func (*Request) Validate

func (req *Request) Validate() error

type Server

type Server struct {
	Domains []string `json:"domains"`

	ProxyAddresses []string `json:"proxy_addresses"`

	NonHTTPSRedirectURL string `json:"non_https_redirect_url"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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