docs: for multiple golang files
	
		
			
	
		
	
	
		
			
				
	
				continuous-integration/drone the build failed
				
					Details
				
			
		
	
				
					
				
			
				
	
				continuous-integration/drone the build failed
				
					Details
				
			
		
	This commit is contained in:
		
							parent
							
								
									d007cc0ce2
								
							
						
					
					
						commit
						d89da311b1
					
				|  | @ -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 { | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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"` | ||||
|  |  | |||
|  | @ -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:"<internal error message>"` | ||||
|  | @ -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" | ||||
| ) | ||||
|  |  | |||
|  | @ -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) | ||||
| } | ||||
|  |  | |||
|  | @ -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 | ||||
| 	} | ||||
| ) | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
|  | @ -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, | ||||
|  |  | |||
|  | @ -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)) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue