From 1259f9cfe3b1f647be8696388623fa86d8eedd83 Mon Sep 17 00:00:00 2001 From: mlabusch Date: Wed, 3 May 2017 07:30:18 +0200 Subject: [PATCH] [Task]: Comment \models --- models/config.go | 23 ++++++++++++----------- models/config_test.go | 2 ++ models/duration.go | 9 ++++----- models/duration_test.go | 3 +++ models/good.go | 12 +++++++----- models/good_test.go | 2 ++ models/main.go | 2 -- models/structstorage.go | 4 ++++ 8 files changed, 34 insertions(+), 23 deletions(-) delete mode 100644 models/main.go create mode 100644 models/structstorage.go diff --git a/models/config.go b/models/config.go index 1d03496..2eb3136 100644 --- a/models/config.go +++ b/models/config.go @@ -1,3 +1,4 @@ +// Package with the mostly static content (models) of this microservice package models import ( @@ -9,9 +10,9 @@ import ( "github.com/genofire/hs_master-kss-monolith/lib/log" ) -//config file of this daemon (for more the config_example.conf in git repository) +// Config file for this daemon (mor information at the config_example.conf in this git repository) type Config struct { - // address on which the api and static content webserver runs + // address under which the api and static content of the webserver runs WebserverBind string `toml:"webserver_bind"` // path to deliver static content @@ -21,33 +22,33 @@ type Config struct { GoodRelease GoodReleaseConfig `toml:"good_release"` CacheClean CacheWorkerConfig `toml:"cache_clean"` - // path to the svg image templaes to show availablity of a given good + // path to the svg image templaes to show availablity of a given good with a traffic light food labeling system GoodAvailablityTemplate string `toml:"good_availablity_template"` - // URLs to other microservices + // URLs to other microservices that this services uses MicroserviceDependencies struct { Product string `toml:"product"` Permission string `toml:"permission"` } `toml:"microservice_dependencies"` } -//config of worker to clean caches from values of other microservice +// Configuration of the Worker to clean the cache from values of other microservice type CacheWorkerConfig struct { - // run worker every ... + // Run Worker every Duration Every Duration - // remove cache which is not used since .. + // Remove cache, which is not used since Duration After Duration } -//config of worker to release looked goods after a time +// Configuration of the Worker to release locked goods after a time period type GoodReleaseConfig struct { - // run worker every ... + // Run worker every Duration Every Duration `toml:"every"` - // unlock which is not used since .. + // unlock which is not used since Duration After Duration `toml:"after"` } -//reads a config model from path of a yml file +// Function that reads a config model from a given path of a yml file func ReadConfigFile(path string) *Config { config := &Config{} file, err := ioutil.ReadFile(path) diff --git a/models/config_test.go b/models/config_test.go index 1b59176..ffd36de 100644 --- a/models/config_test.go +++ b/models/config_test.go @@ -1,3 +1,4 @@ +// Package with the mostly static content (models) of this microservice package models import ( @@ -6,6 +7,7 @@ import ( "github.com/stretchr/testify/assert" ) +// Function to test the configuration of the microservice func TestReadConfig(t *testing.T) { assert := assert.New(t) diff --git a/models/duration.go b/models/duration.go index 965e528..7d0858f 100644 --- a/models/duration.go +++ b/models/duration.go @@ -1,3 +1,4 @@ +// Package with the mostly static content (models) of this microservice package models import ( @@ -7,15 +8,13 @@ import ( ) // Duration is a TOML datatype -// A duration string is a possibly signed sequence of -// decimal numbers and a unit suffix, -// such as "300s", "1.5h" or "5d". -// Valid time units are "s", "m", "h", "d", "w". +// A duration string is a possibly signed sequence of decimal numbers and a unit suffix, +// such as "300s", "1.5h" or "5d". Valid time units are "s", "m", "h", "d", "w". type Duration struct { time.Duration } -// UnmarshalTOML parses a duration string. +// Function UnmarshalTOML parses a duration string func (d *Duration) UnmarshalTOML(dataInterface interface{}) error { var data string switch dataInterface.(type) { diff --git a/models/duration_test.go b/models/duration_test.go index 1296054..e909052 100644 --- a/models/duration_test.go +++ b/models/duration_test.go @@ -1,3 +1,4 @@ +// Package with the mostly static content (models) of this microservice package models import ( @@ -7,6 +8,8 @@ import ( "github.com/stretchr/testify/assert" ) + +// Function to test UnmarshalTOML() func TestDuration(t *testing.T) { assert := assert.New(t) diff --git a/models/good.go b/models/good.go index c3c5bd8..eceb256 100644 --- a/models/good.go +++ b/models/good.go @@ -1,3 +1,4 @@ +// Package with the mostly static content (models) of this microservice package models import ( @@ -9,7 +10,7 @@ import ( "github.com/genofire/hs_master-kss-monolith/lib/database" ) -// this stock microservice manage goods +// Goods managemd in this stock microservice type Good struct { ID int64 ProductID int64 @@ -26,24 +27,24 @@ type Good struct { Sended bool } -// generate database select which filtered locked goods +// Function to enerate a database and select locked goods with a filter func (g *Good) FilterAvailable(db *gorm.DB) *gorm.DB { return db.Model(g).Where("locked_secret == '' OR locked_secret is NULL") } -// lock the good, on a way, that it could not be used by other users +// Function to lock a good, so that it cannot be locked or bought by other users func (g *Good) Lock(secret string) { now := time.Now() g.LockedSecret = secret g.LockedAt = &now } -// is this good locked? +// Function to check if a good is locked func (g *Good) IsLock() bool { return len(g.LockedSecret) > 0 } -// unlock the good, that it could be usered again +// Function to unlock a good func (g *Good) Unlock(secret string) error { if g.LockedSecret == secret { g.LockedSecret = "" @@ -53,6 +54,7 @@ func (g *Good) Unlock(secret string) error { return errors.New("wrong secret") } +// Function to initialize the database func init() { database.AddModel(&Good{}) } diff --git a/models/good_test.go b/models/good_test.go index a020537..9edba5d 100644 --- a/models/good_test.go +++ b/models/good_test.go @@ -1,3 +1,4 @@ +// Package with the mostly static content (models) of this microservice package models import ( @@ -7,6 +8,7 @@ import ( "github.com/stretchr/testify/assert" ) +// Function to test the locking and unlocking of a good func TestGood(t *testing.T) { assert := assert.New(t) diff --git a/models/main.go b/models/main.go deleted file mode 100644 index a6a97ad..0000000 --- a/models/main.go +++ /dev/null @@ -1,2 +0,0 @@ -// a package to store all the struct -package models diff --git a/models/structstorage.go b/models/structstorage.go new file mode 100644 index 0000000..761c714 --- /dev/null +++ b/models/structstorage.go @@ -0,0 +1,4 @@ +// Package with the mostly static content (models) of this microservice +package models + +// Store all the structs