licensr

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

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

Go to latest
Published: Jul 9, 2017 License: BSD-3-Clause Imports: 13 Imported by: 0

README

licnsr - is a simple license managing service (Go) library

Install

go get bitbucket.org/boromil/licensr

Docs

For documentation, please see the package documentation at https://godoc.org/bitbucket.org/boromil/licensr.

Tests

Just use the building Golang test suite:

go run test

run mem/cpu benchmarks with profiling:

go test -bench . -benchmem -cpuprofile prof.cpu -memprofile prof.mem

and for coverage do:

go test -coverprofile=cover.out
go tool cover -html=cover.out

Documentation

Overview

Package licensr provides tools, making it easy for user to create a small license managing service for their application(s).

Index

Constants

This section is empty.

Variables

View Source
var ErrLicenseExists = errors.New("license exists already")

ErrLicenseExists - an error raised when the new license exists already.

Functions

func BoolConverter

func BoolConverter(value string) (interface{}, error)

BoolConverter - converts string to bool - basically a wrapper around strconv.ParseBool.

func DateConverter

func DateConverter(value string) (interface{}, error)

DateConverter - converts string to date. This will return an error if the provided string is in a format other than "2006-01-02".

func GetBodyDefaults

func GetBodyDefaults(bodyDefaultsPath string, defaultBody map[string]interface{}) map[string]interface{}

GetBodyDefaults - returns either default body form a given JSON file or the hardcoded default.

func GetLicenseHandler

func GetLicenseHandler(l Licenser) func(http.ResponseWriter, *http.Request)

GetLicenseHandler - setups and returns a default request handler for the license server.

func InitLicense

func InitLicense(license Licenser, keyName, fileExt, repoPath string, body map[string]interface{}, salt []byte)

InitLicense - helper function, initializes the necessary fields on the Licenser compatible struct.

func IntConverter

func IntConverter(value string) (interface{}, error)

IntConverter - converts string to int - basically a wrapper around strconv.Atoi.

func Serve

func Serve(endpoint, servingAddress string, licenseHandler func(http.ResponseWriter, *http.Request))

Serve - runs the license server using the provided parameters.

func SliceConverter

func SliceConverter(value string) (interface{}, error)

SliceConverter - converts string to slice of strings - example implementation.

Types

type ArgFlags

type ArgFlags struct {
	KeyName, BodyDefaultsPath, Endpoint, NetInterface, Port, FileExt, RepoPath, Salt string
}

ArgFlags - simple struct holding parsed commandline arguments.

func ParseFlags

func ParseFlags() *ArgFlags

ParseFlags - default parser for server commandline arguments.

func (*ArgFlags) ServingAddress

func (af *ArgFlags) ServingAddress() string

ServingAddress - convenience method returning a formatted serving address i.e. localhost:8888.

type FormField

type FormField struct {
	Required, HasDefault bool
	Value                interface{}
	Converter            func(string) (interface{}, error)
}

FormField - a simple struct describing a form field.

func (*FormField) SetValue

func (ff *FormField) SetValue(value string) error

SetValue - if a Converter function has been provided, this method tries to use it, and convert the incoming string to a concrete value type. By default it just passes the value to FormField.Value as a string.

type License

type License struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

License - Main struct, ready for embedding. To fulfill the Licenser interface the end user has to implement GetNewInstance, GetFormFields and GenKey methods.

func (*License) Body

func (l *License) Body() map[string]interface{}

Body - returns the body of the license.

func (*License) Delete

func (l *License) Delete(key string) error

Delete - by default it calls DeleteJSONFile. A good place implement your own license deleting logic.

func (*License) DeleteJSONFile

func (l *License) DeleteJSONFile(key string) error

DeleteJSONFile - Using the provided 'key', deletes the JSON license file.

func (*License) FileExt

func (l *License) FileExt() string

FileExt - returns the file extension used for a license files.

func (*License) Key

func (l *License) Key() string

Key - gets the license key from the body map.

func (*License) KeyName

func (l *License) KeyName() string

KeyName - returns the name of the license key.

func (*License) Load

func (l *License) Load(path string) error

Load - by default it calls LoadJSONFile. A good place implement your own license loading logic.

func (*License) LoadJSONFile

func (l *License) LoadJSONFile(key string) error

LoadJSONFile - loads license from a JSON file.

func (*License) RepoPath

func (l *License) RepoPath() string

RepoPath - returns file path, where the licenses are being stored.

func (*License) Salt

func (l *License) Salt() []byte

Salt - returns a byte slice representing the salt used in license generation process.

func (*License) Save

func (l *License) Save() ([]byte, error)

Save - by default it calls SaveJSONFile. A good place implement your own license saving logic.

func (*License) SaveJSONFile

func (l *License) SaveJSONFile() ([]byte, error)

SaveJSONFile - saves the license as a JSON file.

func (*License) SetBody

func (l *License) SetBody(b map[string]interface{})

SetBody - sets the body of the license.

func (*License) SetFileExt

func (l *License) SetFileExt(fe string)

SetFileExt - Sets the license file extension.

func (*License) SetKey

func (l *License) SetKey(key string)

SetKey - sets the license key in the body map.

func (*License) SetKeyName

func (l *License) SetKeyName(kn string)

SetKeyName - sets the name of the license key.

func (*License) SetRepoPath

func (l *License) SetRepoPath(rp string)

SetRepoPath - sets file path, where the licenses should be stored.

func (*License) SetSalt

func (l *License) SetSalt(s []byte)

SetSalt - sets the salt for the license.

func (*License) Update

func (l *License) Update(cleanedFields map[string]*FormField)

Update - using the provided new values, updates the body map.

type Licenser

type Licenser interface {
	Body() map[string]interface{}
	SetBody(b map[string]interface{})
	Salt() []byte
	SetSalt(s []byte)
	RepoPath() string
	SetRepoPath(rp string)
	FileExt() string
	SetFileExt(fe string)
	KeyName() string
	SetKeyName(keyName string)
	Key() string
	SetKey(key string)
	Load(key string) error
	Save() ([]byte, error)
	Update(cleanedFields map[string]*FormField)
	Delete(key string) error
	GetNewInstance() Licenser
	GetFormFields(requestMethodName string) map[string]*FormField
	GenKey() string
}

Licenser - main interface representing a licence.

Jump to

Keyboard shortcuts

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