changeset 4178:51e90370eced

A few more doc strings to make 'golint' a little bit more happy with the imports package.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 05 Aug 2019 17:45:03 +0200
parents 8b75ac5e243e
children a376351d2774
files pkg/imports/agm.go pkg/imports/config.go pkg/imports/misc.go pkg/imports/modelconvert.go
diffstat 4 files changed, 32 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/imports/agm.go	Mon Aug 05 17:16:46 2019 +0200
+++ b/pkg/imports/agm.go	Mon Aug 05 17:45:03 2019 +0200
@@ -35,6 +35,9 @@
 	"gemma.intevation.de/gemma/pkg/models"
 )
 
+// ApprovedGaugeMeasurements is a Job to import
+// approved gauge measurements from a CVS file
+// into the database.
 type ApprovedGaugeMeasurements struct {
 	Dir        string `json:"dir"`
 	Originator string `json:"originator"`
--- a/pkg/imports/config.go	Mon Aug 05 17:16:46 2019 +0200
+++ b/pkg/imports/config.go	Mon Aug 05 17:45:03 2019 +0200
@@ -29,11 +29,17 @@
 	// of the registered import types.
 	ImportKind string
 
+	// ImportConfigIn is used to de-serialize JSON
+	// configurations coming from the REST endpoints
+	// to be stored in the database.
 	ImportConfigIn struct {
 		Kind   ImportKind      `json:"kind"`
 		Config json.RawMessage `json:"config"`
 	}
 
+	// ImportConfigOut is used to serialize
+	// JSON versions to the REST endpoints
+	// which are stored in the database.
 	ImportConfigOut struct {
 		ID     int64       `json:"id"`
 		Kind   ImportKind  `json:"kind"`
@@ -41,6 +47,9 @@
 		Config interface{} `json:"config,omitempty"`
 	}
 
+	// PersistentConfig is the the in-memory
+	// representation of a configuration
+	// which is stored in the database.
 	PersistentConfig struct {
 		ID         int64
 		User       string
@@ -123,6 +132,7 @@
 VALUES ($1, $2, $3)`
 )
 
+// UpdateContext stores an updated configuration to the database.
 func (pc *PersistentConfig) UpdateContext(ctx context.Context, tx *sql.Tx) error {
 	if _, err := tx.ExecContext(
 		ctx,
@@ -141,6 +151,7 @@
 	return storeConfigAttributes(ctx, tx, pc.ID, pc.Attributes)
 }
 
+// LoadPersistentConfigContext loads a configuration from the database.
 func LoadPersistentConfigContext(
 	ctx context.Context,
 	conn *sql.Conn,
@@ -201,6 +212,9 @@
 	return cfg, err
 }
 
+// ListAllPersistentConfigurationsContext iterates over all
+// configurations stored in the database and reports every
+// particular one to the callback fn.
 func ListAllPersistentConfigurationsContext(
 	ctx context.Context,
 	conn *sql.Conn,
@@ -289,6 +303,9 @@
 	return err
 }
 
+// DeletePersistentConfigurationContext deletes
+// a configuration from the database identified by
+// its id.
 func DeletePersistentConfigurationContext(
 	ctx context.Context,
 	tx *sql.Tx,
@@ -350,6 +367,8 @@
 	return nil
 }
 
+// StoreContext stores a configuration to the database and returns
+// its new database id.
 func (pc *PersistentConfig) StoreContext(ctx context.Context, tx *sql.Tx) (int64, error) {
 	var id int64
 	if err := tx.QueryRowContext(
--- a/pkg/imports/misc.go	Mon Aug 05 17:16:46 2019 +0200
+++ b/pkg/imports/misc.go	Mon Aug 05 17:45:03 2019 +0200
@@ -30,6 +30,12 @@
 	return b.String()
 }
 
+// Savepoint is a function wrapper to hide the details
+// of managing database SAVEPOINTs.
+// If the returned function is called with a callback
+// the callback is run in a SAVEPOINT.
+// If the callback returns w/o an error the SAVEPOINT
+// is released. Otherwise the SAVEPOINT is rolled back.
 func Savepoint(
 	ctx context.Context,
 	tx *sql.Tx,
--- a/pkg/imports/modelconvert.go	Mon Aug 05 17:16:46 2019 +0200
+++ b/pkg/imports/modelconvert.go	Mon Aug 05 17:45:03 2019 +0200
@@ -31,6 +31,8 @@
 	SECJobKind: func() interface{} { return new(models.SectionImport) },
 }
 
+// ImportModelForJobKind returns the constructor function to
+// de-serialize an incoming JSON REST represention of an import.
 func ImportModelForJobKind(kind JobKind) func() interface{} {
 	return kindToImportModel[kind]
 }
@@ -168,6 +170,8 @@
 	return ""
 }
 
+// ConvertToInternal converts an external JSON REST represention
+// of an import into the internal one store in the import queue.
 func ConvertToInternal(kind JobKind, src interface{}) interface{} {
 	fn := convertModel[kind]
 	if fn == nil {