gssc

package module
v0.0.0-...-f3f114d Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2016 License: MIT Imports: 10 Imported by: 2

README

gssc

GoDoc

Easily starts an HTTPS server with self-signed certificates.

Install

go get github.com/mh-cbon/gssc
glide install github.com/mh-cbon/gssc

Usage

package main

import (
  "net/http"
  "crypto/tls"
  "time"
  "github.com/mh-cbon/gssc"
)

var port = ":8080"
var domain = "example.org"

// Example_main demonstrates usage of gssc package.
func main() {
  s := &http.Server{
    Handler: &ww{},
  	Addr: port,
    WriteTimeout: 15 * time.Second,
    ReadTimeout:  15 * time.Second,
  	TLSConfig: &tls.Config{
      InsecureSkipVerify: true,
      GetCertificate: gssc.GetCertificate(domain),
    },
  }
  s.ListenAndServeTLS("", "")
}

type ww struct{}
func (s *ww) ServeHTTP(w http.ResponseWriter, req *http.Request) {
    w.Header().Set("Content-Type", "text/plain")
    w.Write([]byte("This is an example server.\n"))
}

Credits - read more

Documentation

Overview

Get self-signed certificate. Implements tls.Config.GetCertificate to provide an easy way to start an HTTPS server with self-signed certificate.

Example (Main)

Example_main demonstrates usage of gssc package.

package main

import (
	"crypto/tls"
	"github.com/mh-cbon/gssc"
	"net/http"
	"time"
)

var port = ":8080"

// Example_main demonstrates usage of gssc package.
func main() {
	s := &http.Server{
		Handler:      &ww{},
		Addr:         port,
		WriteTimeout: 15 * time.Second,
		ReadTimeout:  15 * time.Second,
		TLSConfig: &tls.Config{
			InsecureSkipVerify: true,
			GetCertificate:     gssc.GetCertificate("example.org"),
		},
	}
	s.ListenAndServeTLS("", "")
}

type ww struct{}

func (s *ww) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	w.Header().Set("Content-Type", "text/plain")
	w.Write([]byte("This is an example server.\n"))
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCertificate

func GetCertificate(arg interface{}) func(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error)

GetCertificte returns a function which generates a self-signed Certificate and implements tls.Config.GetCertificate.

It takes a string(hosname) or a Certopts{} whith more spceific options.

It panics if arg is not a string or a Certopts{}.

Types

type Certopts

type Certopts struct {
	RsaBits   int
	Host      string
	IsCA      bool
	ValidFrom time.Time
	ValidFor  time.Duration
}

Certopts is a struct to define option to generate the certificate.

Jump to

Keyboard shortcuts

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