Documentation ¶
Overview ¶
Package licensr provides tools, making it easy for user to create a small license managing service for their application(s).
Index ¶
- Variables
- func BoolConverter(value string) (interface{}, error)
- func DateConverter(value string) (interface{}, error)
- func GetBodyDefaults(bodyDefaultsPath string, defaultBody map[string]interface{}) map[string]interface{}
- func GetLicenseHandler(l Licenser) func(http.ResponseWriter, *http.Request)
- func InitLicense(license Licenser, keyName, fileExt, repoPath string, ...)
- func IntConverter(value string) (interface{}, error)
- func Serve(endpoint, servingAddress string, ...)
- func SliceConverter(value string) (interface{}, error)
- type ArgFlags
- type FormField
- type License
- func (l *License) Body() map[string]interface{}
- func (l *License) Delete(key string) error
- func (l *License) DeleteJSONFile(key string) error
- func (l *License) FileExt() string
- func (l *License) Key() string
- func (l *License) KeyName() string
- func (l *License) Load(path string) error
- func (l *License) LoadJSONFile(key string) error
- func (l *License) RepoPath() string
- func (l *License) Salt() []byte
- func (l *License) Save() ([]byte, error)
- func (l *License) SaveJSONFile() ([]byte, error)
- func (l *License) SetBody(b map[string]interface{})
- func (l *License) SetFileExt(fe string)
- func (l *License) SetKey(key string)
- func (l *License) SetKeyName(kn string)
- func (l *License) SetRepoPath(rp string)
- func (l *License) SetSalt(s []byte)
- func (l *License) Update(cleanedFields map[string]*FormField)
- type Licenser
Constants ¶
This section is empty.
Variables ¶
var ErrLicenseExists = errors.New("license exists already")
ErrLicenseExists - an error raised when the new license exists already.
Functions ¶
func BoolConverter ¶
BoolConverter - converts string to bool - basically a wrapper around strconv.ParseBool.
func DateConverter ¶
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 ¶
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 ¶
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 ¶
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.
type License ¶
License - Main struct, ready for embedding. To fulfill the Licenser interface the end user has to implement GetNewInstance, GetFormFields and GenKey methods.
func (*License) Delete ¶
Delete - by default it calls DeleteJSONFile. A good place implement your own license deleting logic.
func (*License) DeleteJSONFile ¶
DeleteJSONFile - Using the provided 'key', deletes the JSON license file.
func (*License) Load ¶
Load - by default it calls LoadJSONFile. A good place implement your own license loading logic.
func (*License) LoadJSONFile ¶
LoadJSONFile - loads license from a JSON file.
func (*License) Salt ¶
Salt - returns a byte slice representing the salt used in license generation process.
func (*License) Save ¶
Save - by default it calls SaveJSONFile. A good place implement your own license saving logic.
func (*License) SaveJSONFile ¶
SaveJSONFile - saves the license as a JSON file.
func (*License) SetFileExt ¶
SetFileExt - Sets the license file extension.
func (*License) SetKeyName ¶
SetKeyName - sets the name of the license key.
func (*License) SetRepoPath ¶
SetRepoPath - sets file path, where the licenses should be stored.
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.