diff --git a/database/main.go b/database/main.go index 5f7f4b2..a43de0c 100644 --- a/database/main.go +++ b/database/main.go @@ -7,6 +7,7 @@ import ( "gorm.io/gorm/logger" ) +// Database struct to read from config type Database struct { DB *gorm.DB Connection string `toml:"connection"` @@ -17,6 +18,7 @@ type Database struct { migrationTestdata map[string]*gormigrate.Migration } +// Run database config - connect and migrate func (config *Database) Run() error { db, err := gorm.Open(postgres.Open(config.Connection), &gorm.Config{ Logger: logger.Default.LogMode(config.LogLevel), @@ -36,6 +38,7 @@ func (config *Database) Run() error { return nil } +// Status get status - is database pingable func (config *Database) Status() error { sqlDB, err := config.DB.DB() if err != nil { diff --git a/database/migration.go b/database/migration.go index 87079e8..696fe40 100644 --- a/database/migration.go +++ b/database/migration.go @@ -9,6 +9,7 @@ import ( ) var ( + // ErrNothingToMigrate if nothing has to be migrated ErrNothingToMigrate = errors.New("there is nothing to migrate") ) @@ -28,9 +29,12 @@ func (config *Database) sortedMigration(testdata bool) []*gormigrate.Migration { return migrations } +// Migrate run migration func (config *Database) Migrate() error { return config.migrate(false) } + +// MigrateTestdata run migration and testdata migration func (config *Database) MigrateTestdata() error { return config.migrate(true) } @@ -45,9 +49,12 @@ func (config *Database) migrate(testdata bool) error { return m.Migrate() } +// AddMigration add to database config migration step func (config *Database) AddMigration(m ...*gormigrate.Migration) { config.addMigrate(false, m...) } + +// AddMigrationTestdata add to database config migration step of testdata func (config *Database) AddMigrationTestdata(m ...*gormigrate.Migration) { config.addMigrate(true, m...) } @@ -68,6 +75,7 @@ func (config *Database) addMigrate(testdata bool, m ...*gormigrate.Migration) { } } +// ReRun Rollback und run every migration step again till id func (config *Database) ReRun(id string) { migrations := config.sortedMigration(true) x := 0 diff --git a/web/api/status/main.go b/web/api/status/main.go index ee2691e..e333fe9 100644 --- a/web/api/status/main.go +++ b/web/api/status/main.go @@ -9,13 +9,17 @@ import ( ) var ( - VERSION string = "" - UP func() bool = func() bool { + // VERSION string on status API + VERSION string = "" + // UP function to detect, if API is healthy + UP func() bool = func() bool { return true } + // EXTRAS show more informations in status EXTRAS interface{} = nil ) +// Status API response type Status struct { Version string `json:"version"` Up bool `json:"up"` diff --git a/web/error.go b/web/error.go index 738eada..474a94e 100644 --- a/web/error.go +++ b/web/error.go @@ -1,5 +1,6 @@ package web +// HTTPError as a response, with data type HTTPError struct { Message string `json:"message" example:"invalid format"` Error string `json:"error,omitempty" example:""` @@ -7,7 +8,10 @@ type HTTPError struct { } const ( + // APIErrorInvalidRequestFormat const for api error with invalid request format APIErrorInvalidRequestFormat = "Invalid Request Format" - APIErrorInternalDatabase = "Internal Database Error" - APIErrorNotFound = "Not found" + // APIErrorInternalDatabase const for api error with problem with database + APIErrorInternalDatabase = "Internal Database Error" + // APIErrorNotFound const for api error with not found object + APIErrorNotFound = "Not found" ) diff --git a/web/main.go b/web/main.go index e00d22b..049c034 100644 --- a/web/main.go +++ b/web/main.go @@ -55,7 +55,6 @@ func (config *Service) Run() error { Cache: autocert.DirCache(config.ACME.Cache), } return autotls.RunWithManager(r, &m) - } else { - return r.Run(config.Listen) } + return r.Run(config.Listen) } diff --git a/web/metrics/main.go b/web/metrics/main.go index dfe6860..9fc9f34 100644 --- a/web/metrics/main.go +++ b/web/metrics/main.go @@ -17,9 +17,12 @@ import ( ) var ( - NAMESPACE string = "service" - VERSION string = "" - UP func() bool = func() bool { + // NAMESPACE of prometheus metrics + NAMESPACE string = "service" + // VERSION in prometheus metrics + VERSION string = "" + // UP function for healthy check in prometheus metrics + UP func() bool = func() bool { return true } ) diff --git a/web/module.go b/web/module.go index 02ffc27..cda7486 100644 --- a/web/module.go +++ b/web/module.go @@ -10,12 +10,15 @@ var ( modules []ModuleRegisterFunc ) +// ModuleRegisterFunc format of module which registerd to WebService type ModuleRegisterFunc func(*gin.Engine, *Service) +// ModuleRegister used on start of WebService func ModuleRegister(f ModuleRegisterFunc) { modules = append(modules, f) } +// Bind WebService to gin.Engine func (ws *Service) Bind(r *gin.Engine) { for _, f := range modules { f(r, ws) diff --git a/web/request.go b/web/request.go index 6b7183d..3c812fc 100644 --- a/web/request.go +++ b/web/request.go @@ -6,6 +6,7 @@ import ( "time" ) +// JSONRequest easy get request for json func JSONRequest(url string, value interface{}) error { var netClient = &http.Client{ Timeout: time.Second * 20, diff --git a/web/session.go b/web/session.go index d0a9206..0dbd77b 100644 --- a/web/session.go +++ b/web/session.go @@ -6,6 +6,7 @@ import ( "github.com/gin-gonic/gin" ) +// LoadSession module to start Session Handling in WebService func (config *Service) LoadSession(r *gin.Engine) { store := cookie.NewStore([]byte(config.Session.Secret)) r.Use(sessions.Sessions(config.Session.Name, store))