feat(healthcheck): initial demo cronjob execution

This commit is contained in:
Tine 2024-02-16 13:07:29 +01:00
parent ccce0440f8
commit 224f1f93fa
Signed by: mentos1386
SSH key fingerprint: SHA256:MNtTsLbihYaWF8j1fkOHfkKNlnN1JQfxEU/rBU8nCGw
23 changed files with 2069 additions and 378 deletions

View file

@ -23,7 +23,12 @@ func main() {
}
log.Println("Connected to database")
h := handlers.NewBaseHandler(db, query, cfg)
temporalClient, err := internal.ConnectToTemporal(cfg)
if err != nil {
log.Fatal(err)
}
h := handlers.NewBaseHandler(db, query, temporalClient, cfg)
// Health
r.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {

View file

@ -3,11 +3,11 @@ package main
import (
"log"
"code.tjo.space/mentos1386/zdravko/internal"
"code.tjo.space/mentos1386/zdravko/internal/config"
t "code.tjo.space/mentos1386/zdravko/pkg/temporal"
)
func backendServer(config *internal.Config) {
func backendServer(config *config.Config) {
serverConfig := t.NewServerConfig(config)
server, err := t.NewServer(serverConfig)
@ -26,7 +26,7 @@ func backendServer(config *internal.Config) {
}
}
func frontendServer(config *internal.Config) {
func frontendServer(config *config.Config) {
uiConfig := t.NewUiConfig(config)
uiServer, err := t.NewUiServer(uiConfig)
@ -43,7 +43,7 @@ func frontendServer(config *internal.Config) {
}
func main() {
config := internal.NewConfig()
config := config.NewConfig()
go func() {
frontendServer(config)

View file

@ -3,13 +3,15 @@ package main
import (
"log"
"code.tjo.space/mentos1386/zdravko/internal"
"code.tjo.space/mentos1386/zdravko/internal/activities"
"code.tjo.space/mentos1386/zdravko/internal/config"
"code.tjo.space/mentos1386/zdravko/internal/workflows"
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/worker"
)
func main() {
config := internal.NewConfig()
config := config.NewConfig()
// Initialize a Temporal Client
// Specify the Namespace in the Client options
@ -25,14 +27,16 @@ func main() {
// Create a new Worker
// TODO: Maybe identify by region or something?
yourWorker := worker.New(temporalClient, "default", worker.Options{})
w := worker.New(temporalClient, "default", worker.Options{})
// Register Workflows
//yourWorker.RegisterWorkflow(workflows.default)
w.RegisterWorkflow(workflows.HealthcheckHttpWorkflowDefinition)
// Register Activities
//yourWorker.RegisterActivity(activities.SSNTraceActivity)
w.RegisterActivity(activities.HealthcheckHttpActivityDefinition)
// Start the the Worker Process
err = yourWorker.Run(worker.InterruptCh())
err = w.Run(worker.InterruptCh())
if err != nil {
log.Fatalln("Unable to start the Worker Process", err)
}

View file

@ -0,0 +1,39 @@
package activities
import (
"context"
"net/http"
)
type HealtcheckHttpActivityParam struct {
Url string
Method string
}
type HealthcheckHttpActivityResult struct {
Success bool
}
func HealthcheckHttpActivityDefinition(ctx context.Context, param HealtcheckHttpActivityParam) (*HealthcheckHttpActivityResult, error) {
if param.Method == "" {
param.Method = "GET"
}
var (
response *http.Response
err error
)
switch param.Method {
case "GET":
response, err = http.Get(param.Url)
case "POST":
response, err = http.Post(param.Url, "application/json", nil)
}
if err != nil {
return nil, err
}
return &HealthcheckHttpActivityResult{Success: response.StatusCode == 200}, nil
}

View file

@ -15,10 +15,13 @@ func ConnectToDatabase(path string) (*gorm.DB, *query.Query, error) {
}
err = db.AutoMigrate(
&models.HealthcheckHTTP{},
&models.HealthcheckTCP{},
&models.Cronjob{},
&models.OAuth2State{},
models.HealthcheckHttp{},
models.HealthcheckHttpHistory{},
models.HealthcheckTcp{},
models.HealthcheckTcpHistory{},
models.Cronjob{},
models.CronjobHistory{},
models.OAuth2State{},
)
if err != nil {
return nil, nil, err

View file

@ -5,6 +5,7 @@ import (
"code.tjo.space/mentos1386/zdravko/internal/models/query"
"code.tjo.space/mentos1386/zdravko/web/templates/components"
"github.com/gorilla/sessions"
"go.temporal.io/sdk/client"
"gorm.io/gorm"
)
@ -28,11 +29,13 @@ type BaseHandler struct {
query *query.Query
config *config.Config
temporal client.Client
store *sessions.CookieStore
}
func NewBaseHandler(db *gorm.DB, q *query.Query, config *config.Config) *BaseHandler {
func NewBaseHandler(db *gorm.DB, q *query.Query, temporal client.Client, config *config.Config) *BaseHandler {
store := sessions.NewCookieStore([]byte(config.SessionSecret))
return &BaseHandler{db, q, config, store}
return &BaseHandler{db, q, config, temporal, store}
}

View file

@ -3,11 +3,13 @@ package handlers
import (
"context"
"fmt"
"log"
"net/http"
"strconv"
"text/template"
"code.tjo.space/mentos1386/zdravko/internal/models"
"code.tjo.space/mentos1386/zdravko/internal/services"
"code.tjo.space/mentos1386/zdravko/web/templates"
"code.tjo.space/mentos1386/zdravko/web/templates/components"
"github.com/gorilla/mux"
@ -15,13 +17,13 @@ import (
type SettingsHealthchecks struct {
*Settings
Healthchecks []*models.HealthcheckHTTP
Healthchecks []*models.HealthcheckHttp
HealthchecksLength int
}
type SettingsHealthcheck struct {
*Settings
Healthcheck *models.HealthcheckHTTP
Healthcheck *models.HealthcheckHttp
}
func (h *BaseHandler) SettingsHealthchecksGET(w http.ResponseWriter, r *http.Request, user *AuthenticatedUser) {
@ -35,7 +37,7 @@ func (h *BaseHandler) SettingsHealthchecksGET(w http.ResponseWriter, r *http.Req
return
}
healthchecks, err := h.query.HealthcheckHTTP.WithContext(context.Background()).Find()
healthchecks, err := h.query.HealthcheckHttp.WithContext(context.Background()).Find()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
@ -71,9 +73,7 @@ func (h *BaseHandler) SettingsHealthchecksDescribeGET(w http.ResponseWriter, r *
return
}
healthcheck, err := h.query.HealthcheckHTTP.WithContext(context.Background()).Where(
h.query.HealthcheckHTTP.ID.Eq(uint(id)),
).First()
healthcheck, err := services.GetHealthcheckHttp(context.Background(), h.query, uint(id))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
@ -84,7 +84,7 @@ func (h *BaseHandler) SettingsHealthchecksDescribeGET(w http.ResponseWriter, r *
GetPageByTitle(SettingsPages, "Healthchecks"),
[]*components.Page{
GetPageByTitle(SettingsPages, "Healthchecks"),
&components.Page{
{
Path: fmt.Sprintf("/settings/healthchecks/%d", id),
Title: "Describe",
Breadcrumb: healthcheck.Name,
@ -122,15 +122,28 @@ func (h *BaseHandler) SettingsHealthchecksCreateGET(w http.ResponseWriter, r *ht
}
func (h *BaseHandler) SettingsHealthchecksCreatePOST(w http.ResponseWriter, r *http.Request, user *AuthenticatedUser) {
healthcheck := &models.HealthcheckHTTP{
Healthcheck: models.Healthcheck{
Name: r.FormValue("name"),
Schedule: r.FormValue("schedule"),
},
URL: r.FormValue("url"),
Method: r.FormValue("method"),
ctx := context.Background()
err := services.CreateHealthcheckHttp(
ctx,
h.db,
&models.HealthcheckHttp{
Healthcheck: models.Healthcheck{
Name: r.FormValue("name"),
Schedule: r.FormValue("schedule"),
},
URL: r.FormValue("url"),
Method: r.FormValue("method"),
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
err = services.StartHealthcheckHttp(ctx, h.temporal)
if err != nil {
log.Println("Error starting healthcheck workflow", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
h.db.Create(healthcheck)
http.Redirect(w, r, "/settings/healthchecks", http.StatusSeeOther)
}

View file

@ -19,14 +19,14 @@ type Healthcheck struct {
Schedule string
}
type HealthcheckHTTP struct {
type HealthcheckHttp struct {
gorm.Model
Healthcheck
URL string
Method string
}
type HealthcheckTCP struct {
type HealthcheckTcp struct {
gorm.Model
Healthcheck
Hostname string
@ -39,3 +39,21 @@ type Cronjob struct {
Schedule string
Buffer int
}
type HealthcheckHttpHistory struct {
gorm.Model
HealthcheckHTTP HealthcheckHttp `gorm:"foreignkey:ID"`
Status string
}
type HealthcheckTcpHistory struct {
gorm.Model
HealthcheckTCP HealthcheckTcp `gorm:"foreignkey:ID"`
Status string
}
type CronjobHistory struct {
gorm.Model
Cronjob Cronjob `gorm:"foreignkey:ID"`
Status string
}

View file

@ -0,0 +1,486 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"code.tjo.space/mentos1386/zdravko/internal/models"
)
func newCronjobHistory(db *gorm.DB, opts ...gen.DOOption) cronjobHistory {
_cronjobHistory := cronjobHistory{}
_cronjobHistory.cronjobHistoryDo.UseDB(db, opts...)
_cronjobHistory.cronjobHistoryDo.UseModel(&models.CronjobHistory{})
tableName := _cronjobHistory.cronjobHistoryDo.TableName()
_cronjobHistory.ALL = field.NewAsterisk(tableName)
_cronjobHistory.ID = field.NewUint(tableName, "id")
_cronjobHistory.CreatedAt = field.NewTime(tableName, "created_at")
_cronjobHistory.UpdatedAt = field.NewTime(tableName, "updated_at")
_cronjobHistory.DeletedAt = field.NewField(tableName, "deleted_at")
_cronjobHistory.Status = field.NewString(tableName, "status")
_cronjobHistory.Cronjob = cronjobHistoryHasOneCronjob{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("Cronjob", "models.Cronjob"),
}
_cronjobHistory.fillFieldMap()
return _cronjobHistory
}
type cronjobHistory struct {
cronjobHistoryDo cronjobHistoryDo
ALL field.Asterisk
ID field.Uint
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
Status field.String
Cronjob cronjobHistoryHasOneCronjob
fieldMap map[string]field.Expr
}
func (c cronjobHistory) Table(newTableName string) *cronjobHistory {
c.cronjobHistoryDo.UseTable(newTableName)
return c.updateTableName(newTableName)
}
func (c cronjobHistory) As(alias string) *cronjobHistory {
c.cronjobHistoryDo.DO = *(c.cronjobHistoryDo.As(alias).(*gen.DO))
return c.updateTableName(alias)
}
func (c *cronjobHistory) updateTableName(table string) *cronjobHistory {
c.ALL = field.NewAsterisk(table)
c.ID = field.NewUint(table, "id")
c.CreatedAt = field.NewTime(table, "created_at")
c.UpdatedAt = field.NewTime(table, "updated_at")
c.DeletedAt = field.NewField(table, "deleted_at")
c.Status = field.NewString(table, "status")
c.fillFieldMap()
return c
}
func (c *cronjobHistory) WithContext(ctx context.Context) ICronjobHistoryDo {
return c.cronjobHistoryDo.WithContext(ctx)
}
func (c cronjobHistory) TableName() string { return c.cronjobHistoryDo.TableName() }
func (c cronjobHistory) Alias() string { return c.cronjobHistoryDo.Alias() }
func (c cronjobHistory) Columns(cols ...field.Expr) gen.Columns {
return c.cronjobHistoryDo.Columns(cols...)
}
func (c *cronjobHistory) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := c.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (c *cronjobHistory) fillFieldMap() {
c.fieldMap = make(map[string]field.Expr, 6)
c.fieldMap["id"] = c.ID
c.fieldMap["created_at"] = c.CreatedAt
c.fieldMap["updated_at"] = c.UpdatedAt
c.fieldMap["deleted_at"] = c.DeletedAt
c.fieldMap["status"] = c.Status
}
func (c cronjobHistory) clone(db *gorm.DB) cronjobHistory {
c.cronjobHistoryDo.ReplaceConnPool(db.Statement.ConnPool)
return c
}
func (c cronjobHistory) replaceDB(db *gorm.DB) cronjobHistory {
c.cronjobHistoryDo.ReplaceDB(db)
return c
}
type cronjobHistoryHasOneCronjob struct {
db *gorm.DB
field.RelationField
}
func (a cronjobHistoryHasOneCronjob) Where(conds ...field.Expr) *cronjobHistoryHasOneCronjob {
if len(conds) == 0 {
return &a
}
exprs := make([]clause.Expression, 0, len(conds))
for _, cond := range conds {
exprs = append(exprs, cond.BeCond().(clause.Expression))
}
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
return &a
}
func (a cronjobHistoryHasOneCronjob) WithContext(ctx context.Context) *cronjobHistoryHasOneCronjob {
a.db = a.db.WithContext(ctx)
return &a
}
func (a cronjobHistoryHasOneCronjob) Session(session *gorm.Session) *cronjobHistoryHasOneCronjob {
a.db = a.db.Session(session)
return &a
}
func (a cronjobHistoryHasOneCronjob) Model(m *models.CronjobHistory) *cronjobHistoryHasOneCronjobTx {
return &cronjobHistoryHasOneCronjobTx{a.db.Model(m).Association(a.Name())}
}
type cronjobHistoryHasOneCronjobTx struct{ tx *gorm.Association }
func (a cronjobHistoryHasOneCronjobTx) Find() (result *models.Cronjob, err error) {
return result, a.tx.Find(&result)
}
func (a cronjobHistoryHasOneCronjobTx) Append(values ...*models.Cronjob) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Append(targetValues...)
}
func (a cronjobHistoryHasOneCronjobTx) Replace(values ...*models.Cronjob) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Replace(targetValues...)
}
func (a cronjobHistoryHasOneCronjobTx) Delete(values ...*models.Cronjob) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Delete(targetValues...)
}
func (a cronjobHistoryHasOneCronjobTx) Clear() error {
return a.tx.Clear()
}
func (a cronjobHistoryHasOneCronjobTx) Count() int64 {
return a.tx.Count()
}
type cronjobHistoryDo struct{ gen.DO }
type ICronjobHistoryDo interface {
gen.SubQuery
Debug() ICronjobHistoryDo
WithContext(ctx context.Context) ICronjobHistoryDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() ICronjobHistoryDo
WriteDB() ICronjobHistoryDo
As(alias string) gen.Dao
Session(config *gorm.Session) ICronjobHistoryDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) ICronjobHistoryDo
Not(conds ...gen.Condition) ICronjobHistoryDo
Or(conds ...gen.Condition) ICronjobHistoryDo
Select(conds ...field.Expr) ICronjobHistoryDo
Where(conds ...gen.Condition) ICronjobHistoryDo
Order(conds ...field.Expr) ICronjobHistoryDo
Distinct(cols ...field.Expr) ICronjobHistoryDo
Omit(cols ...field.Expr) ICronjobHistoryDo
Join(table schema.Tabler, on ...field.Expr) ICronjobHistoryDo
LeftJoin(table schema.Tabler, on ...field.Expr) ICronjobHistoryDo
RightJoin(table schema.Tabler, on ...field.Expr) ICronjobHistoryDo
Group(cols ...field.Expr) ICronjobHistoryDo
Having(conds ...gen.Condition) ICronjobHistoryDo
Limit(limit int) ICronjobHistoryDo
Offset(offset int) ICronjobHistoryDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) ICronjobHistoryDo
Unscoped() ICronjobHistoryDo
Create(values ...*models.CronjobHistory) error
CreateInBatches(values []*models.CronjobHistory, batchSize int) error
Save(values ...*models.CronjobHistory) error
First() (*models.CronjobHistory, error)
Take() (*models.CronjobHistory, error)
Last() (*models.CronjobHistory, error)
Find() ([]*models.CronjobHistory, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.CronjobHistory, err error)
FindInBatches(result *[]*models.CronjobHistory, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*models.CronjobHistory) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) ICronjobHistoryDo
Assign(attrs ...field.AssignExpr) ICronjobHistoryDo
Joins(fields ...field.RelationField) ICronjobHistoryDo
Preload(fields ...field.RelationField) ICronjobHistoryDo
FirstOrInit() (*models.CronjobHistory, error)
FirstOrCreate() (*models.CronjobHistory, error)
FindByPage(offset int, limit int) (result []*models.CronjobHistory, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) ICronjobHistoryDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (c cronjobHistoryDo) Debug() ICronjobHistoryDo {
return c.withDO(c.DO.Debug())
}
func (c cronjobHistoryDo) WithContext(ctx context.Context) ICronjobHistoryDo {
return c.withDO(c.DO.WithContext(ctx))
}
func (c cronjobHistoryDo) ReadDB() ICronjobHistoryDo {
return c.Clauses(dbresolver.Read)
}
func (c cronjobHistoryDo) WriteDB() ICronjobHistoryDo {
return c.Clauses(dbresolver.Write)
}
func (c cronjobHistoryDo) Session(config *gorm.Session) ICronjobHistoryDo {
return c.withDO(c.DO.Session(config))
}
func (c cronjobHistoryDo) Clauses(conds ...clause.Expression) ICronjobHistoryDo {
return c.withDO(c.DO.Clauses(conds...))
}
func (c cronjobHistoryDo) Returning(value interface{}, columns ...string) ICronjobHistoryDo {
return c.withDO(c.DO.Returning(value, columns...))
}
func (c cronjobHistoryDo) Not(conds ...gen.Condition) ICronjobHistoryDo {
return c.withDO(c.DO.Not(conds...))
}
func (c cronjobHistoryDo) Or(conds ...gen.Condition) ICronjobHistoryDo {
return c.withDO(c.DO.Or(conds...))
}
func (c cronjobHistoryDo) Select(conds ...field.Expr) ICronjobHistoryDo {
return c.withDO(c.DO.Select(conds...))
}
func (c cronjobHistoryDo) Where(conds ...gen.Condition) ICronjobHistoryDo {
return c.withDO(c.DO.Where(conds...))
}
func (c cronjobHistoryDo) Order(conds ...field.Expr) ICronjobHistoryDo {
return c.withDO(c.DO.Order(conds...))
}
func (c cronjobHistoryDo) Distinct(cols ...field.Expr) ICronjobHistoryDo {
return c.withDO(c.DO.Distinct(cols...))
}
func (c cronjobHistoryDo) Omit(cols ...field.Expr) ICronjobHistoryDo {
return c.withDO(c.DO.Omit(cols...))
}
func (c cronjobHistoryDo) Join(table schema.Tabler, on ...field.Expr) ICronjobHistoryDo {
return c.withDO(c.DO.Join(table, on...))
}
func (c cronjobHistoryDo) LeftJoin(table schema.Tabler, on ...field.Expr) ICronjobHistoryDo {
return c.withDO(c.DO.LeftJoin(table, on...))
}
func (c cronjobHistoryDo) RightJoin(table schema.Tabler, on ...field.Expr) ICronjobHistoryDo {
return c.withDO(c.DO.RightJoin(table, on...))
}
func (c cronjobHistoryDo) Group(cols ...field.Expr) ICronjobHistoryDo {
return c.withDO(c.DO.Group(cols...))
}
func (c cronjobHistoryDo) Having(conds ...gen.Condition) ICronjobHistoryDo {
return c.withDO(c.DO.Having(conds...))
}
func (c cronjobHistoryDo) Limit(limit int) ICronjobHistoryDo {
return c.withDO(c.DO.Limit(limit))
}
func (c cronjobHistoryDo) Offset(offset int) ICronjobHistoryDo {
return c.withDO(c.DO.Offset(offset))
}
func (c cronjobHistoryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ICronjobHistoryDo {
return c.withDO(c.DO.Scopes(funcs...))
}
func (c cronjobHistoryDo) Unscoped() ICronjobHistoryDo {
return c.withDO(c.DO.Unscoped())
}
func (c cronjobHistoryDo) Create(values ...*models.CronjobHistory) error {
if len(values) == 0 {
return nil
}
return c.DO.Create(values)
}
func (c cronjobHistoryDo) CreateInBatches(values []*models.CronjobHistory, batchSize int) error {
return c.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (c cronjobHistoryDo) Save(values ...*models.CronjobHistory) error {
if len(values) == 0 {
return nil
}
return c.DO.Save(values)
}
func (c cronjobHistoryDo) First() (*models.CronjobHistory, error) {
if result, err := c.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.CronjobHistory), nil
}
}
func (c cronjobHistoryDo) Take() (*models.CronjobHistory, error) {
if result, err := c.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.CronjobHistory), nil
}
}
func (c cronjobHistoryDo) Last() (*models.CronjobHistory, error) {
if result, err := c.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.CronjobHistory), nil
}
}
func (c cronjobHistoryDo) Find() ([]*models.CronjobHistory, error) {
result, err := c.DO.Find()
return result.([]*models.CronjobHistory), err
}
func (c cronjobHistoryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.CronjobHistory, err error) {
buf := make([]*models.CronjobHistory, 0, batchSize)
err = c.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (c cronjobHistoryDo) FindInBatches(result *[]*models.CronjobHistory, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return c.DO.FindInBatches(result, batchSize, fc)
}
func (c cronjobHistoryDo) Attrs(attrs ...field.AssignExpr) ICronjobHistoryDo {
return c.withDO(c.DO.Attrs(attrs...))
}
func (c cronjobHistoryDo) Assign(attrs ...field.AssignExpr) ICronjobHistoryDo {
return c.withDO(c.DO.Assign(attrs...))
}
func (c cronjobHistoryDo) Joins(fields ...field.RelationField) ICronjobHistoryDo {
for _, _f := range fields {
c = *c.withDO(c.DO.Joins(_f))
}
return &c
}
func (c cronjobHistoryDo) Preload(fields ...field.RelationField) ICronjobHistoryDo {
for _, _f := range fields {
c = *c.withDO(c.DO.Preload(_f))
}
return &c
}
func (c cronjobHistoryDo) FirstOrInit() (*models.CronjobHistory, error) {
if result, err := c.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.CronjobHistory), nil
}
}
func (c cronjobHistoryDo) FirstOrCreate() (*models.CronjobHistory, error) {
if result, err := c.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.CronjobHistory), nil
}
}
func (c cronjobHistoryDo) FindByPage(offset int, limit int) (result []*models.CronjobHistory, count int64, err error) {
result, err = c.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = c.Offset(-1).Limit(-1).Count()
return
}
func (c cronjobHistoryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = c.Count()
if err != nil {
return
}
err = c.Offset(offset).Limit(limit).Scan(result)
return
}
func (c cronjobHistoryDo) Scan(result interface{}) (err error) {
return c.DO.Scan(result)
}
func (c cronjobHistoryDo) Delete(models ...*models.CronjobHistory) (result gen.ResultInfo, err error) {
return c.DO.Delete(models)
}
func (c *cronjobHistoryDo) withDO(do gen.Dao) *cronjobHistoryDo {
c.DO = *do.(*gen.DO)
return c
}

View file

@ -16,49 +16,64 @@ import (
)
var (
Q = new(Query)
Cronjob *cronjob
HealthcheckHTTP *healthcheckHTTP
HealthcheckTCP *healthcheckTCP
OAuth2State *oAuth2State
Q = new(Query)
Cronjob *cronjob
CronjobHistory *cronjobHistory
HealthcheckHttp *healthcheckHttp
HealthcheckHttpHistory *healthcheckHttpHistory
HealthcheckTcp *healthcheckTcp
HealthcheckTcpHistory *healthcheckTcpHistory
OAuth2State *oAuth2State
)
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
Cronjob = &Q.Cronjob
HealthcheckHTTP = &Q.HealthcheckHTTP
HealthcheckTCP = &Q.HealthcheckTCP
CronjobHistory = &Q.CronjobHistory
HealthcheckHttp = &Q.HealthcheckHttp
HealthcheckHttpHistory = &Q.HealthcheckHttpHistory
HealthcheckTcp = &Q.HealthcheckTcp
HealthcheckTcpHistory = &Q.HealthcheckTcpHistory
OAuth2State = &Q.OAuth2State
}
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
Cronjob: newCronjob(db, opts...),
HealthcheckHTTP: newHealthcheckHTTP(db, opts...),
HealthcheckTCP: newHealthcheckTCP(db, opts...),
OAuth2State: newOAuth2State(db, opts...),
db: db,
Cronjob: newCronjob(db, opts...),
CronjobHistory: newCronjobHistory(db, opts...),
HealthcheckHttp: newHealthcheckHttp(db, opts...),
HealthcheckHttpHistory: newHealthcheckHttpHistory(db, opts...),
HealthcheckTcp: newHealthcheckTcp(db, opts...),
HealthcheckTcpHistory: newHealthcheckTcpHistory(db, opts...),
OAuth2State: newOAuth2State(db, opts...),
}
}
type Query struct {
db *gorm.DB
Cronjob cronjob
HealthcheckHTTP healthcheckHTTP
HealthcheckTCP healthcheckTCP
OAuth2State oAuth2State
Cronjob cronjob
CronjobHistory cronjobHistory
HealthcheckHttp healthcheckHttp
HealthcheckHttpHistory healthcheckHttpHistory
HealthcheckTcp healthcheckTcp
HealthcheckTcpHistory healthcheckTcpHistory
OAuth2State oAuth2State
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
Cronjob: q.Cronjob.clone(db),
HealthcheckHTTP: q.HealthcheckHTTP.clone(db),
HealthcheckTCP: q.HealthcheckTCP.clone(db),
OAuth2State: q.OAuth2State.clone(db),
db: db,
Cronjob: q.Cronjob.clone(db),
CronjobHistory: q.CronjobHistory.clone(db),
HealthcheckHttp: q.HealthcheckHttp.clone(db),
HealthcheckHttpHistory: q.HealthcheckHttpHistory.clone(db),
HealthcheckTcp: q.HealthcheckTcp.clone(db),
HealthcheckTcpHistory: q.HealthcheckTcpHistory.clone(db),
OAuth2State: q.OAuth2State.clone(db),
}
}
@ -72,27 +87,36 @@ func (q *Query) WriteDB() *Query {
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
Cronjob: q.Cronjob.replaceDB(db),
HealthcheckHTTP: q.HealthcheckHTTP.replaceDB(db),
HealthcheckTCP: q.HealthcheckTCP.replaceDB(db),
OAuth2State: q.OAuth2State.replaceDB(db),
db: db,
Cronjob: q.Cronjob.replaceDB(db),
CronjobHistory: q.CronjobHistory.replaceDB(db),
HealthcheckHttp: q.HealthcheckHttp.replaceDB(db),
HealthcheckHttpHistory: q.HealthcheckHttpHistory.replaceDB(db),
HealthcheckTcp: q.HealthcheckTcp.replaceDB(db),
HealthcheckTcpHistory: q.HealthcheckTcpHistory.replaceDB(db),
OAuth2State: q.OAuth2State.replaceDB(db),
}
}
type queryCtx struct {
Cronjob ICronjobDo
HealthcheckHTTP IHealthcheckHTTPDo
HealthcheckTCP IHealthcheckTCPDo
OAuth2State IOAuth2StateDo
Cronjob ICronjobDo
CronjobHistory ICronjobHistoryDo
HealthcheckHttp IHealthcheckHttpDo
HealthcheckHttpHistory IHealthcheckHttpHistoryDo
HealthcheckTcp IHealthcheckTcpDo
HealthcheckTcpHistory IHealthcheckTcpHistoryDo
OAuth2State IOAuth2StateDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
Cronjob: q.Cronjob.WithContext(ctx),
HealthcheckHTTP: q.HealthcheckHTTP.WithContext(ctx),
HealthcheckTCP: q.HealthcheckTCP.WithContext(ctx),
OAuth2State: q.OAuth2State.WithContext(ctx),
Cronjob: q.Cronjob.WithContext(ctx),
CronjobHistory: q.CronjobHistory.WithContext(ctx),
HealthcheckHttp: q.HealthcheckHttp.WithContext(ctx),
HealthcheckHttpHistory: q.HealthcheckHttpHistory.WithContext(ctx),
HealthcheckTcp: q.HealthcheckTcp.WithContext(ctx),
HealthcheckTcpHistory: q.HealthcheckTcpHistory.WithContext(ctx),
OAuth2State: q.OAuth2State.WithContext(ctx),
}
}

View file

@ -0,0 +1,486 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"code.tjo.space/mentos1386/zdravko/internal/models"
)
func newHealthcheckHttpHistory(db *gorm.DB, opts ...gen.DOOption) healthcheckHttpHistory {
_healthcheckHttpHistory := healthcheckHttpHistory{}
_healthcheckHttpHistory.healthcheckHttpHistoryDo.UseDB(db, opts...)
_healthcheckHttpHistory.healthcheckHttpHistoryDo.UseModel(&models.HealthcheckHttpHistory{})
tableName := _healthcheckHttpHistory.healthcheckHttpHistoryDo.TableName()
_healthcheckHttpHistory.ALL = field.NewAsterisk(tableName)
_healthcheckHttpHistory.ID = field.NewUint(tableName, "id")
_healthcheckHttpHistory.CreatedAt = field.NewTime(tableName, "created_at")
_healthcheckHttpHistory.UpdatedAt = field.NewTime(tableName, "updated_at")
_healthcheckHttpHistory.DeletedAt = field.NewField(tableName, "deleted_at")
_healthcheckHttpHistory.Status = field.NewString(tableName, "status")
_healthcheckHttpHistory.HealthcheckHTTP = healthcheckHttpHistoryHasOneHealthcheckHTTP{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("HealthcheckHTTP", "models.HealthcheckHttp"),
}
_healthcheckHttpHistory.fillFieldMap()
return _healthcheckHttpHistory
}
type healthcheckHttpHistory struct {
healthcheckHttpHistoryDo healthcheckHttpHistoryDo
ALL field.Asterisk
ID field.Uint
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
Status field.String
HealthcheckHTTP healthcheckHttpHistoryHasOneHealthcheckHTTP
fieldMap map[string]field.Expr
}
func (h healthcheckHttpHistory) Table(newTableName string) *healthcheckHttpHistory {
h.healthcheckHttpHistoryDo.UseTable(newTableName)
return h.updateTableName(newTableName)
}
func (h healthcheckHttpHistory) As(alias string) *healthcheckHttpHistory {
h.healthcheckHttpHistoryDo.DO = *(h.healthcheckHttpHistoryDo.As(alias).(*gen.DO))
return h.updateTableName(alias)
}
func (h *healthcheckHttpHistory) updateTableName(table string) *healthcheckHttpHistory {
h.ALL = field.NewAsterisk(table)
h.ID = field.NewUint(table, "id")
h.CreatedAt = field.NewTime(table, "created_at")
h.UpdatedAt = field.NewTime(table, "updated_at")
h.DeletedAt = field.NewField(table, "deleted_at")
h.Status = field.NewString(table, "status")
h.fillFieldMap()
return h
}
func (h *healthcheckHttpHistory) WithContext(ctx context.Context) IHealthcheckHttpHistoryDo {
return h.healthcheckHttpHistoryDo.WithContext(ctx)
}
func (h healthcheckHttpHistory) TableName() string { return h.healthcheckHttpHistoryDo.TableName() }
func (h healthcheckHttpHistory) Alias() string { return h.healthcheckHttpHistoryDo.Alias() }
func (h healthcheckHttpHistory) Columns(cols ...field.Expr) gen.Columns {
return h.healthcheckHttpHistoryDo.Columns(cols...)
}
func (h *healthcheckHttpHistory) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := h.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (h *healthcheckHttpHistory) fillFieldMap() {
h.fieldMap = make(map[string]field.Expr, 6)
h.fieldMap["id"] = h.ID
h.fieldMap["created_at"] = h.CreatedAt
h.fieldMap["updated_at"] = h.UpdatedAt
h.fieldMap["deleted_at"] = h.DeletedAt
h.fieldMap["status"] = h.Status
}
func (h healthcheckHttpHistory) clone(db *gorm.DB) healthcheckHttpHistory {
h.healthcheckHttpHistoryDo.ReplaceConnPool(db.Statement.ConnPool)
return h
}
func (h healthcheckHttpHistory) replaceDB(db *gorm.DB) healthcheckHttpHistory {
h.healthcheckHttpHistoryDo.ReplaceDB(db)
return h
}
type healthcheckHttpHistoryHasOneHealthcheckHTTP struct {
db *gorm.DB
field.RelationField
}
func (a healthcheckHttpHistoryHasOneHealthcheckHTTP) Where(conds ...field.Expr) *healthcheckHttpHistoryHasOneHealthcheckHTTP {
if len(conds) == 0 {
return &a
}
exprs := make([]clause.Expression, 0, len(conds))
for _, cond := range conds {
exprs = append(exprs, cond.BeCond().(clause.Expression))
}
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
return &a
}
func (a healthcheckHttpHistoryHasOneHealthcheckHTTP) WithContext(ctx context.Context) *healthcheckHttpHistoryHasOneHealthcheckHTTP {
a.db = a.db.WithContext(ctx)
return &a
}
func (a healthcheckHttpHistoryHasOneHealthcheckHTTP) Session(session *gorm.Session) *healthcheckHttpHistoryHasOneHealthcheckHTTP {
a.db = a.db.Session(session)
return &a
}
func (a healthcheckHttpHistoryHasOneHealthcheckHTTP) Model(m *models.HealthcheckHttpHistory) *healthcheckHttpHistoryHasOneHealthcheckHTTPTx {
return &healthcheckHttpHistoryHasOneHealthcheckHTTPTx{a.db.Model(m).Association(a.Name())}
}
type healthcheckHttpHistoryHasOneHealthcheckHTTPTx struct{ tx *gorm.Association }
func (a healthcheckHttpHistoryHasOneHealthcheckHTTPTx) Find() (result *models.HealthcheckHttp, err error) {
return result, a.tx.Find(&result)
}
func (a healthcheckHttpHistoryHasOneHealthcheckHTTPTx) Append(values ...*models.HealthcheckHttp) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Append(targetValues...)
}
func (a healthcheckHttpHistoryHasOneHealthcheckHTTPTx) Replace(values ...*models.HealthcheckHttp) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Replace(targetValues...)
}
func (a healthcheckHttpHistoryHasOneHealthcheckHTTPTx) Delete(values ...*models.HealthcheckHttp) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Delete(targetValues...)
}
func (a healthcheckHttpHistoryHasOneHealthcheckHTTPTx) Clear() error {
return a.tx.Clear()
}
func (a healthcheckHttpHistoryHasOneHealthcheckHTTPTx) Count() int64 {
return a.tx.Count()
}
type healthcheckHttpHistoryDo struct{ gen.DO }
type IHealthcheckHttpHistoryDo interface {
gen.SubQuery
Debug() IHealthcheckHttpHistoryDo
WithContext(ctx context.Context) IHealthcheckHttpHistoryDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IHealthcheckHttpHistoryDo
WriteDB() IHealthcheckHttpHistoryDo
As(alias string) gen.Dao
Session(config *gorm.Session) IHealthcheckHttpHistoryDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IHealthcheckHttpHistoryDo
Not(conds ...gen.Condition) IHealthcheckHttpHistoryDo
Or(conds ...gen.Condition) IHealthcheckHttpHistoryDo
Select(conds ...field.Expr) IHealthcheckHttpHistoryDo
Where(conds ...gen.Condition) IHealthcheckHttpHistoryDo
Order(conds ...field.Expr) IHealthcheckHttpHistoryDo
Distinct(cols ...field.Expr) IHealthcheckHttpHistoryDo
Omit(cols ...field.Expr) IHealthcheckHttpHistoryDo
Join(table schema.Tabler, on ...field.Expr) IHealthcheckHttpHistoryDo
LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHttpHistoryDo
RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHttpHistoryDo
Group(cols ...field.Expr) IHealthcheckHttpHistoryDo
Having(conds ...gen.Condition) IHealthcheckHttpHistoryDo
Limit(limit int) IHealthcheckHttpHistoryDo
Offset(offset int) IHealthcheckHttpHistoryDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckHttpHistoryDo
Unscoped() IHealthcheckHttpHistoryDo
Create(values ...*models.HealthcheckHttpHistory) error
CreateInBatches(values []*models.HealthcheckHttpHistory, batchSize int) error
Save(values ...*models.HealthcheckHttpHistory) error
First() (*models.HealthcheckHttpHistory, error)
Take() (*models.HealthcheckHttpHistory, error)
Last() (*models.HealthcheckHttpHistory, error)
Find() ([]*models.HealthcheckHttpHistory, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckHttpHistory, err error)
FindInBatches(result *[]*models.HealthcheckHttpHistory, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*models.HealthcheckHttpHistory) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) IHealthcheckHttpHistoryDo
Assign(attrs ...field.AssignExpr) IHealthcheckHttpHistoryDo
Joins(fields ...field.RelationField) IHealthcheckHttpHistoryDo
Preload(fields ...field.RelationField) IHealthcheckHttpHistoryDo
FirstOrInit() (*models.HealthcheckHttpHistory, error)
FirstOrCreate() (*models.HealthcheckHttpHistory, error)
FindByPage(offset int, limit int) (result []*models.HealthcheckHttpHistory, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) IHealthcheckHttpHistoryDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (h healthcheckHttpHistoryDo) Debug() IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Debug())
}
func (h healthcheckHttpHistoryDo) WithContext(ctx context.Context) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.WithContext(ctx))
}
func (h healthcheckHttpHistoryDo) ReadDB() IHealthcheckHttpHistoryDo {
return h.Clauses(dbresolver.Read)
}
func (h healthcheckHttpHistoryDo) WriteDB() IHealthcheckHttpHistoryDo {
return h.Clauses(dbresolver.Write)
}
func (h healthcheckHttpHistoryDo) Session(config *gorm.Session) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Session(config))
}
func (h healthcheckHttpHistoryDo) Clauses(conds ...clause.Expression) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Clauses(conds...))
}
func (h healthcheckHttpHistoryDo) Returning(value interface{}, columns ...string) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Returning(value, columns...))
}
func (h healthcheckHttpHistoryDo) Not(conds ...gen.Condition) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Not(conds...))
}
func (h healthcheckHttpHistoryDo) Or(conds ...gen.Condition) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Or(conds...))
}
func (h healthcheckHttpHistoryDo) Select(conds ...field.Expr) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Select(conds...))
}
func (h healthcheckHttpHistoryDo) Where(conds ...gen.Condition) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Where(conds...))
}
func (h healthcheckHttpHistoryDo) Order(conds ...field.Expr) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Order(conds...))
}
func (h healthcheckHttpHistoryDo) Distinct(cols ...field.Expr) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Distinct(cols...))
}
func (h healthcheckHttpHistoryDo) Omit(cols ...field.Expr) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Omit(cols...))
}
func (h healthcheckHttpHistoryDo) Join(table schema.Tabler, on ...field.Expr) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Join(table, on...))
}
func (h healthcheckHttpHistoryDo) LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.LeftJoin(table, on...))
}
func (h healthcheckHttpHistoryDo) RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.RightJoin(table, on...))
}
func (h healthcheckHttpHistoryDo) Group(cols ...field.Expr) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Group(cols...))
}
func (h healthcheckHttpHistoryDo) Having(conds ...gen.Condition) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Having(conds...))
}
func (h healthcheckHttpHistoryDo) Limit(limit int) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Limit(limit))
}
func (h healthcheckHttpHistoryDo) Offset(offset int) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Offset(offset))
}
func (h healthcheckHttpHistoryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Scopes(funcs...))
}
func (h healthcheckHttpHistoryDo) Unscoped() IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Unscoped())
}
func (h healthcheckHttpHistoryDo) Create(values ...*models.HealthcheckHttpHistory) error {
if len(values) == 0 {
return nil
}
return h.DO.Create(values)
}
func (h healthcheckHttpHistoryDo) CreateInBatches(values []*models.HealthcheckHttpHistory, batchSize int) error {
return h.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (h healthcheckHttpHistoryDo) Save(values ...*models.HealthcheckHttpHistory) error {
if len(values) == 0 {
return nil
}
return h.DO.Save(values)
}
func (h healthcheckHttpHistoryDo) First() (*models.HealthcheckHttpHistory, error) {
if result, err := h.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckHttpHistory), nil
}
}
func (h healthcheckHttpHistoryDo) Take() (*models.HealthcheckHttpHistory, error) {
if result, err := h.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckHttpHistory), nil
}
}
func (h healthcheckHttpHistoryDo) Last() (*models.HealthcheckHttpHistory, error) {
if result, err := h.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckHttpHistory), nil
}
}
func (h healthcheckHttpHistoryDo) Find() ([]*models.HealthcheckHttpHistory, error) {
result, err := h.DO.Find()
return result.([]*models.HealthcheckHttpHistory), err
}
func (h healthcheckHttpHistoryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckHttpHistory, err error) {
buf := make([]*models.HealthcheckHttpHistory, 0, batchSize)
err = h.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (h healthcheckHttpHistoryDo) FindInBatches(result *[]*models.HealthcheckHttpHistory, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return h.DO.FindInBatches(result, batchSize, fc)
}
func (h healthcheckHttpHistoryDo) Attrs(attrs ...field.AssignExpr) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Attrs(attrs...))
}
func (h healthcheckHttpHistoryDo) Assign(attrs ...field.AssignExpr) IHealthcheckHttpHistoryDo {
return h.withDO(h.DO.Assign(attrs...))
}
func (h healthcheckHttpHistoryDo) Joins(fields ...field.RelationField) IHealthcheckHttpHistoryDo {
for _, _f := range fields {
h = *h.withDO(h.DO.Joins(_f))
}
return &h
}
func (h healthcheckHttpHistoryDo) Preload(fields ...field.RelationField) IHealthcheckHttpHistoryDo {
for _, _f := range fields {
h = *h.withDO(h.DO.Preload(_f))
}
return &h
}
func (h healthcheckHttpHistoryDo) FirstOrInit() (*models.HealthcheckHttpHistory, error) {
if result, err := h.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckHttpHistory), nil
}
}
func (h healthcheckHttpHistoryDo) FirstOrCreate() (*models.HealthcheckHttpHistory, error) {
if result, err := h.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckHttpHistory), nil
}
}
func (h healthcheckHttpHistoryDo) FindByPage(offset int, limit int) (result []*models.HealthcheckHttpHistory, count int64, err error) {
result, err = h.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = h.Offset(-1).Limit(-1).Count()
return
}
func (h healthcheckHttpHistoryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = h.Count()
if err != nil {
return
}
err = h.Offset(offset).Limit(limit).Scan(result)
return
}
func (h healthcheckHttpHistoryDo) Scan(result interface{}) (err error) {
return h.DO.Scan(result)
}
func (h healthcheckHttpHistoryDo) Delete(models ...*models.HealthcheckHttpHistory) (result gen.ResultInfo, err error) {
return h.DO.Delete(models)
}
func (h *healthcheckHttpHistoryDo) withDO(do gen.Dao) *healthcheckHttpHistoryDo {
h.DO = *do.(*gen.DO)
return h
}

View file

@ -19,32 +19,32 @@ import (
"code.tjo.space/mentos1386/zdravko/internal/models"
)
func newHealthcheckHTTP(db *gorm.DB, opts ...gen.DOOption) healthcheckHTTP {
_healthcheckHTTP := healthcheckHTTP{}
func newHealthcheckHttp(db *gorm.DB, opts ...gen.DOOption) healthcheckHttp {
_healthcheckHttp := healthcheckHttp{}
_healthcheckHTTP.healthcheckHTTPDo.UseDB(db, opts...)
_healthcheckHTTP.healthcheckHTTPDo.UseModel(&models.HealthcheckHTTP{})
_healthcheckHttp.healthcheckHttpDo.UseDB(db, opts...)
_healthcheckHttp.healthcheckHttpDo.UseModel(&models.HealthcheckHttp{})
tableName := _healthcheckHTTP.healthcheckHTTPDo.TableName()
_healthcheckHTTP.ALL = field.NewAsterisk(tableName)
_healthcheckHTTP.ID = field.NewUint(tableName, "id")
_healthcheckHTTP.CreatedAt = field.NewTime(tableName, "created_at")
_healthcheckHTTP.UpdatedAt = field.NewTime(tableName, "updated_at")
_healthcheckHTTP.DeletedAt = field.NewField(tableName, "deleted_at")
_healthcheckHTTP.Name = field.NewString(tableName, "name")
_healthcheckHTTP.Status = field.NewString(tableName, "status")
_healthcheckHTTP.UptimePercentage = field.NewFloat64(tableName, "uptime_percentage")
_healthcheckHTTP.Schedule = field.NewString(tableName, "schedule")
_healthcheckHTTP.URL = field.NewString(tableName, "url")
_healthcheckHTTP.Method = field.NewString(tableName, "method")
tableName := _healthcheckHttp.healthcheckHttpDo.TableName()
_healthcheckHttp.ALL = field.NewAsterisk(tableName)
_healthcheckHttp.ID = field.NewUint(tableName, "id")
_healthcheckHttp.CreatedAt = field.NewTime(tableName, "created_at")
_healthcheckHttp.UpdatedAt = field.NewTime(tableName, "updated_at")
_healthcheckHttp.DeletedAt = field.NewField(tableName, "deleted_at")
_healthcheckHttp.Name = field.NewString(tableName, "name")
_healthcheckHttp.Status = field.NewString(tableName, "status")
_healthcheckHttp.UptimePercentage = field.NewFloat64(tableName, "uptime_percentage")
_healthcheckHttp.Schedule = field.NewString(tableName, "schedule")
_healthcheckHttp.URL = field.NewString(tableName, "url")
_healthcheckHttp.Method = field.NewString(tableName, "method")
_healthcheckHTTP.fillFieldMap()
_healthcheckHttp.fillFieldMap()
return _healthcheckHTTP
return _healthcheckHttp
}
type healthcheckHTTP struct {
healthcheckHTTPDo healthcheckHTTPDo
type healthcheckHttp struct {
healthcheckHttpDo healthcheckHttpDo
ALL field.Asterisk
ID field.Uint
@ -61,17 +61,17 @@ type healthcheckHTTP struct {
fieldMap map[string]field.Expr
}
func (h healthcheckHTTP) Table(newTableName string) *healthcheckHTTP {
h.healthcheckHTTPDo.UseTable(newTableName)
func (h healthcheckHttp) Table(newTableName string) *healthcheckHttp {
h.healthcheckHttpDo.UseTable(newTableName)
return h.updateTableName(newTableName)
}
func (h healthcheckHTTP) As(alias string) *healthcheckHTTP {
h.healthcheckHTTPDo.DO = *(h.healthcheckHTTPDo.As(alias).(*gen.DO))
func (h healthcheckHttp) As(alias string) *healthcheckHttp {
h.healthcheckHttpDo.DO = *(h.healthcheckHttpDo.As(alias).(*gen.DO))
return h.updateTableName(alias)
}
func (h *healthcheckHTTP) updateTableName(table string) *healthcheckHTTP {
func (h *healthcheckHttp) updateTableName(table string) *healthcheckHttp {
h.ALL = field.NewAsterisk(table)
h.ID = field.NewUint(table, "id")
h.CreatedAt = field.NewTime(table, "created_at")
@ -89,19 +89,19 @@ func (h *healthcheckHTTP) updateTableName(table string) *healthcheckHTTP {
return h
}
func (h *healthcheckHTTP) WithContext(ctx context.Context) IHealthcheckHTTPDo {
return h.healthcheckHTTPDo.WithContext(ctx)
func (h *healthcheckHttp) WithContext(ctx context.Context) IHealthcheckHttpDo {
return h.healthcheckHttpDo.WithContext(ctx)
}
func (h healthcheckHTTP) TableName() string { return h.healthcheckHTTPDo.TableName() }
func (h healthcheckHttp) TableName() string { return h.healthcheckHttpDo.TableName() }
func (h healthcheckHTTP) Alias() string { return h.healthcheckHTTPDo.Alias() }
func (h healthcheckHttp) Alias() string { return h.healthcheckHttpDo.Alias() }
func (h healthcheckHTTP) Columns(cols ...field.Expr) gen.Columns {
return h.healthcheckHTTPDo.Columns(cols...)
func (h healthcheckHttp) Columns(cols ...field.Expr) gen.Columns {
return h.healthcheckHttpDo.Columns(cols...)
}
func (h *healthcheckHTTP) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
func (h *healthcheckHttp) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := h.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
@ -110,7 +110,7 @@ func (h *healthcheckHTTP) GetFieldByName(fieldName string) (field.OrderExpr, boo
return _oe, ok
}
func (h *healthcheckHTTP) fillFieldMap() {
func (h *healthcheckHttp) fillFieldMap() {
h.fieldMap = make(map[string]field.Expr, 10)
h.fieldMap["id"] = h.ID
h.fieldMap["created_at"] = h.CreatedAt
@ -124,58 +124,58 @@ func (h *healthcheckHTTP) fillFieldMap() {
h.fieldMap["method"] = h.Method
}
func (h healthcheckHTTP) clone(db *gorm.DB) healthcheckHTTP {
h.healthcheckHTTPDo.ReplaceConnPool(db.Statement.ConnPool)
func (h healthcheckHttp) clone(db *gorm.DB) healthcheckHttp {
h.healthcheckHttpDo.ReplaceConnPool(db.Statement.ConnPool)
return h
}
func (h healthcheckHTTP) replaceDB(db *gorm.DB) healthcheckHTTP {
h.healthcheckHTTPDo.ReplaceDB(db)
func (h healthcheckHttp) replaceDB(db *gorm.DB) healthcheckHttp {
h.healthcheckHttpDo.ReplaceDB(db)
return h
}
type healthcheckHTTPDo struct{ gen.DO }
type healthcheckHttpDo struct{ gen.DO }
type IHealthcheckHTTPDo interface {
type IHealthcheckHttpDo interface {
gen.SubQuery
Debug() IHealthcheckHTTPDo
WithContext(ctx context.Context) IHealthcheckHTTPDo
Debug() IHealthcheckHttpDo
WithContext(ctx context.Context) IHealthcheckHttpDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IHealthcheckHTTPDo
WriteDB() IHealthcheckHTTPDo
ReadDB() IHealthcheckHttpDo
WriteDB() IHealthcheckHttpDo
As(alias string) gen.Dao
Session(config *gorm.Session) IHealthcheckHTTPDo
Session(config *gorm.Session) IHealthcheckHttpDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IHealthcheckHTTPDo
Not(conds ...gen.Condition) IHealthcheckHTTPDo
Or(conds ...gen.Condition) IHealthcheckHTTPDo
Select(conds ...field.Expr) IHealthcheckHTTPDo
Where(conds ...gen.Condition) IHealthcheckHTTPDo
Order(conds ...field.Expr) IHealthcheckHTTPDo
Distinct(cols ...field.Expr) IHealthcheckHTTPDo
Omit(cols ...field.Expr) IHealthcheckHTTPDo
Join(table schema.Tabler, on ...field.Expr) IHealthcheckHTTPDo
LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHTTPDo
RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHTTPDo
Group(cols ...field.Expr) IHealthcheckHTTPDo
Having(conds ...gen.Condition) IHealthcheckHTTPDo
Limit(limit int) IHealthcheckHTTPDo
Offset(offset int) IHealthcheckHTTPDo
Clauses(conds ...clause.Expression) IHealthcheckHttpDo
Not(conds ...gen.Condition) IHealthcheckHttpDo
Or(conds ...gen.Condition) IHealthcheckHttpDo
Select(conds ...field.Expr) IHealthcheckHttpDo
Where(conds ...gen.Condition) IHealthcheckHttpDo
Order(conds ...field.Expr) IHealthcheckHttpDo
Distinct(cols ...field.Expr) IHealthcheckHttpDo
Omit(cols ...field.Expr) IHealthcheckHttpDo
Join(table schema.Tabler, on ...field.Expr) IHealthcheckHttpDo
LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHttpDo
RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHttpDo
Group(cols ...field.Expr) IHealthcheckHttpDo
Having(conds ...gen.Condition) IHealthcheckHttpDo
Limit(limit int) IHealthcheckHttpDo
Offset(offset int) IHealthcheckHttpDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckHTTPDo
Unscoped() IHealthcheckHTTPDo
Create(values ...*models.HealthcheckHTTP) error
CreateInBatches(values []*models.HealthcheckHTTP, batchSize int) error
Save(values ...*models.HealthcheckHTTP) error
First() (*models.HealthcheckHTTP, error)
Take() (*models.HealthcheckHTTP, error)
Last() (*models.HealthcheckHTTP, error)
Find() ([]*models.HealthcheckHTTP, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckHTTP, err error)
FindInBatches(result *[]*models.HealthcheckHTTP, batchSize int, fc func(tx gen.Dao, batch int) error) error
Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckHttpDo
Unscoped() IHealthcheckHttpDo
Create(values ...*models.HealthcheckHttp) error
CreateInBatches(values []*models.HealthcheckHttp, batchSize int) error
Save(values ...*models.HealthcheckHttp) error
First() (*models.HealthcheckHttp, error)
Take() (*models.HealthcheckHttp, error)
Last() (*models.HealthcheckHttp, error)
Find() ([]*models.HealthcheckHttp, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckHttp, err error)
FindInBatches(result *[]*models.HealthcheckHttp, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*models.HealthcheckHTTP) (info gen.ResultInfo, err error)
Delete(...*models.HealthcheckHttp) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
@ -183,163 +183,163 @@ type IHealthcheckHTTPDo interface {
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) IHealthcheckHTTPDo
Assign(attrs ...field.AssignExpr) IHealthcheckHTTPDo
Joins(fields ...field.RelationField) IHealthcheckHTTPDo
Preload(fields ...field.RelationField) IHealthcheckHTTPDo
FirstOrInit() (*models.HealthcheckHTTP, error)
FirstOrCreate() (*models.HealthcheckHTTP, error)
FindByPage(offset int, limit int) (result []*models.HealthcheckHTTP, count int64, err error)
Attrs(attrs ...field.AssignExpr) IHealthcheckHttpDo
Assign(attrs ...field.AssignExpr) IHealthcheckHttpDo
Joins(fields ...field.RelationField) IHealthcheckHttpDo
Preload(fields ...field.RelationField) IHealthcheckHttpDo
FirstOrInit() (*models.HealthcheckHttp, error)
FirstOrCreate() (*models.HealthcheckHttp, error)
FindByPage(offset int, limit int) (result []*models.HealthcheckHttp, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) IHealthcheckHTTPDo
Returning(value interface{}, columns ...string) IHealthcheckHttpDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (h healthcheckHTTPDo) Debug() IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Debug() IHealthcheckHttpDo {
return h.withDO(h.DO.Debug())
}
func (h healthcheckHTTPDo) WithContext(ctx context.Context) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) WithContext(ctx context.Context) IHealthcheckHttpDo {
return h.withDO(h.DO.WithContext(ctx))
}
func (h healthcheckHTTPDo) ReadDB() IHealthcheckHTTPDo {
func (h healthcheckHttpDo) ReadDB() IHealthcheckHttpDo {
return h.Clauses(dbresolver.Read)
}
func (h healthcheckHTTPDo) WriteDB() IHealthcheckHTTPDo {
func (h healthcheckHttpDo) WriteDB() IHealthcheckHttpDo {
return h.Clauses(dbresolver.Write)
}
func (h healthcheckHTTPDo) Session(config *gorm.Session) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Session(config *gorm.Session) IHealthcheckHttpDo {
return h.withDO(h.DO.Session(config))
}
func (h healthcheckHTTPDo) Clauses(conds ...clause.Expression) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Clauses(conds ...clause.Expression) IHealthcheckHttpDo {
return h.withDO(h.DO.Clauses(conds...))
}
func (h healthcheckHTTPDo) Returning(value interface{}, columns ...string) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Returning(value interface{}, columns ...string) IHealthcheckHttpDo {
return h.withDO(h.DO.Returning(value, columns...))
}
func (h healthcheckHTTPDo) Not(conds ...gen.Condition) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Not(conds ...gen.Condition) IHealthcheckHttpDo {
return h.withDO(h.DO.Not(conds...))
}
func (h healthcheckHTTPDo) Or(conds ...gen.Condition) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Or(conds ...gen.Condition) IHealthcheckHttpDo {
return h.withDO(h.DO.Or(conds...))
}
func (h healthcheckHTTPDo) Select(conds ...field.Expr) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Select(conds ...field.Expr) IHealthcheckHttpDo {
return h.withDO(h.DO.Select(conds...))
}
func (h healthcheckHTTPDo) Where(conds ...gen.Condition) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Where(conds ...gen.Condition) IHealthcheckHttpDo {
return h.withDO(h.DO.Where(conds...))
}
func (h healthcheckHTTPDo) Order(conds ...field.Expr) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Order(conds ...field.Expr) IHealthcheckHttpDo {
return h.withDO(h.DO.Order(conds...))
}
func (h healthcheckHTTPDo) Distinct(cols ...field.Expr) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Distinct(cols ...field.Expr) IHealthcheckHttpDo {
return h.withDO(h.DO.Distinct(cols...))
}
func (h healthcheckHTTPDo) Omit(cols ...field.Expr) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Omit(cols ...field.Expr) IHealthcheckHttpDo {
return h.withDO(h.DO.Omit(cols...))
}
func (h healthcheckHTTPDo) Join(table schema.Tabler, on ...field.Expr) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Join(table schema.Tabler, on ...field.Expr) IHealthcheckHttpDo {
return h.withDO(h.DO.Join(table, on...))
}
func (h healthcheckHTTPDo) LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHttpDo {
return h.withDO(h.DO.LeftJoin(table, on...))
}
func (h healthcheckHTTPDo) RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckHttpDo {
return h.withDO(h.DO.RightJoin(table, on...))
}
func (h healthcheckHTTPDo) Group(cols ...field.Expr) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Group(cols ...field.Expr) IHealthcheckHttpDo {
return h.withDO(h.DO.Group(cols...))
}
func (h healthcheckHTTPDo) Having(conds ...gen.Condition) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Having(conds ...gen.Condition) IHealthcheckHttpDo {
return h.withDO(h.DO.Having(conds...))
}
func (h healthcheckHTTPDo) Limit(limit int) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Limit(limit int) IHealthcheckHttpDo {
return h.withDO(h.DO.Limit(limit))
}
func (h healthcheckHTTPDo) Offset(offset int) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Offset(offset int) IHealthcheckHttpDo {
return h.withDO(h.DO.Offset(offset))
}
func (h healthcheckHTTPDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckHttpDo {
return h.withDO(h.DO.Scopes(funcs...))
}
func (h healthcheckHTTPDo) Unscoped() IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Unscoped() IHealthcheckHttpDo {
return h.withDO(h.DO.Unscoped())
}
func (h healthcheckHTTPDo) Create(values ...*models.HealthcheckHTTP) error {
func (h healthcheckHttpDo) Create(values ...*models.HealthcheckHttp) error {
if len(values) == 0 {
return nil
}
return h.DO.Create(values)
}
func (h healthcheckHTTPDo) CreateInBatches(values []*models.HealthcheckHTTP, batchSize int) error {
func (h healthcheckHttpDo) CreateInBatches(values []*models.HealthcheckHttp, batchSize int) error {
return h.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (h healthcheckHTTPDo) Save(values ...*models.HealthcheckHTTP) error {
func (h healthcheckHttpDo) Save(values ...*models.HealthcheckHttp) error {
if len(values) == 0 {
return nil
}
return h.DO.Save(values)
}
func (h healthcheckHTTPDo) First() (*models.HealthcheckHTTP, error) {
func (h healthcheckHttpDo) First() (*models.HealthcheckHttp, error) {
if result, err := h.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckHTTP), nil
return result.(*models.HealthcheckHttp), nil
}
}
func (h healthcheckHTTPDo) Take() (*models.HealthcheckHTTP, error) {
func (h healthcheckHttpDo) Take() (*models.HealthcheckHttp, error) {
if result, err := h.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckHTTP), nil
return result.(*models.HealthcheckHttp), nil
}
}
func (h healthcheckHTTPDo) Last() (*models.HealthcheckHTTP, error) {
func (h healthcheckHttpDo) Last() (*models.HealthcheckHttp, error) {
if result, err := h.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckHTTP), nil
return result.(*models.HealthcheckHttp), nil
}
}
func (h healthcheckHTTPDo) Find() ([]*models.HealthcheckHTTP, error) {
func (h healthcheckHttpDo) Find() ([]*models.HealthcheckHttp, error) {
result, err := h.DO.Find()
return result.([]*models.HealthcheckHTTP), err
return result.([]*models.HealthcheckHttp), err
}
func (h healthcheckHTTPDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckHTTP, err error) {
buf := make([]*models.HealthcheckHTTP, 0, batchSize)
func (h healthcheckHttpDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckHttp, err error) {
buf := make([]*models.HealthcheckHttp, 0, batchSize)
err = h.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
@ -347,49 +347,49 @@ func (h healthcheckHTTPDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch
return results, err
}
func (h healthcheckHTTPDo) FindInBatches(result *[]*models.HealthcheckHTTP, batchSize int, fc func(tx gen.Dao, batch int) error) error {
func (h healthcheckHttpDo) FindInBatches(result *[]*models.HealthcheckHttp, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return h.DO.FindInBatches(result, batchSize, fc)
}
func (h healthcheckHTTPDo) Attrs(attrs ...field.AssignExpr) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Attrs(attrs ...field.AssignExpr) IHealthcheckHttpDo {
return h.withDO(h.DO.Attrs(attrs...))
}
func (h healthcheckHTTPDo) Assign(attrs ...field.AssignExpr) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Assign(attrs ...field.AssignExpr) IHealthcheckHttpDo {
return h.withDO(h.DO.Assign(attrs...))
}
func (h healthcheckHTTPDo) Joins(fields ...field.RelationField) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Joins(fields ...field.RelationField) IHealthcheckHttpDo {
for _, _f := range fields {
h = *h.withDO(h.DO.Joins(_f))
}
return &h
}
func (h healthcheckHTTPDo) Preload(fields ...field.RelationField) IHealthcheckHTTPDo {
func (h healthcheckHttpDo) Preload(fields ...field.RelationField) IHealthcheckHttpDo {
for _, _f := range fields {
h = *h.withDO(h.DO.Preload(_f))
}
return &h
}
func (h healthcheckHTTPDo) FirstOrInit() (*models.HealthcheckHTTP, error) {
func (h healthcheckHttpDo) FirstOrInit() (*models.HealthcheckHttp, error) {
if result, err := h.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckHTTP), nil
return result.(*models.HealthcheckHttp), nil
}
}
func (h healthcheckHTTPDo) FirstOrCreate() (*models.HealthcheckHTTP, error) {
func (h healthcheckHttpDo) FirstOrCreate() (*models.HealthcheckHttp, error) {
if result, err := h.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckHTTP), nil
return result.(*models.HealthcheckHttp), nil
}
}
func (h healthcheckHTTPDo) FindByPage(offset int, limit int) (result []*models.HealthcheckHTTP, count int64, err error) {
func (h healthcheckHttpDo) FindByPage(offset int, limit int) (result []*models.HealthcheckHttp, count int64, err error) {
result, err = h.Offset(offset).Limit(limit).Find()
if err != nil {
return
@ -404,7 +404,7 @@ func (h healthcheckHTTPDo) FindByPage(offset int, limit int) (result []*models.H
return
}
func (h healthcheckHTTPDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
func (h healthcheckHttpDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = h.Count()
if err != nil {
return
@ -414,15 +414,15 @@ func (h healthcheckHTTPDo) ScanByPage(result interface{}, offset int, limit int)
return
}
func (h healthcheckHTTPDo) Scan(result interface{}) (err error) {
func (h healthcheckHttpDo) Scan(result interface{}) (err error) {
return h.DO.Scan(result)
}
func (h healthcheckHTTPDo) Delete(models ...*models.HealthcheckHTTP) (result gen.ResultInfo, err error) {
func (h healthcheckHttpDo) Delete(models ...*models.HealthcheckHttp) (result gen.ResultInfo, err error) {
return h.DO.Delete(models)
}
func (h *healthcheckHTTPDo) withDO(do gen.Dao) *healthcheckHTTPDo {
func (h *healthcheckHttpDo) withDO(do gen.Dao) *healthcheckHttpDo {
h.DO = *do.(*gen.DO)
return h
}

View file

@ -0,0 +1,486 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"code.tjo.space/mentos1386/zdravko/internal/models"
)
func newHealthcheckTcpHistory(db *gorm.DB, opts ...gen.DOOption) healthcheckTcpHistory {
_healthcheckTcpHistory := healthcheckTcpHistory{}
_healthcheckTcpHistory.healthcheckTcpHistoryDo.UseDB(db, opts...)
_healthcheckTcpHistory.healthcheckTcpHistoryDo.UseModel(&models.HealthcheckTcpHistory{})
tableName := _healthcheckTcpHistory.healthcheckTcpHistoryDo.TableName()
_healthcheckTcpHistory.ALL = field.NewAsterisk(tableName)
_healthcheckTcpHistory.ID = field.NewUint(tableName, "id")
_healthcheckTcpHistory.CreatedAt = field.NewTime(tableName, "created_at")
_healthcheckTcpHistory.UpdatedAt = field.NewTime(tableName, "updated_at")
_healthcheckTcpHistory.DeletedAt = field.NewField(tableName, "deleted_at")
_healthcheckTcpHistory.Status = field.NewString(tableName, "status")
_healthcheckTcpHistory.HealthcheckTCP = healthcheckTcpHistoryHasOneHealthcheckTCP{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("HealthcheckTCP", "models.HealthcheckTcp"),
}
_healthcheckTcpHistory.fillFieldMap()
return _healthcheckTcpHistory
}
type healthcheckTcpHistory struct {
healthcheckTcpHistoryDo healthcheckTcpHistoryDo
ALL field.Asterisk
ID field.Uint
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
Status field.String
HealthcheckTCP healthcheckTcpHistoryHasOneHealthcheckTCP
fieldMap map[string]field.Expr
}
func (h healthcheckTcpHistory) Table(newTableName string) *healthcheckTcpHistory {
h.healthcheckTcpHistoryDo.UseTable(newTableName)
return h.updateTableName(newTableName)
}
func (h healthcheckTcpHistory) As(alias string) *healthcheckTcpHistory {
h.healthcheckTcpHistoryDo.DO = *(h.healthcheckTcpHistoryDo.As(alias).(*gen.DO))
return h.updateTableName(alias)
}
func (h *healthcheckTcpHistory) updateTableName(table string) *healthcheckTcpHistory {
h.ALL = field.NewAsterisk(table)
h.ID = field.NewUint(table, "id")
h.CreatedAt = field.NewTime(table, "created_at")
h.UpdatedAt = field.NewTime(table, "updated_at")
h.DeletedAt = field.NewField(table, "deleted_at")
h.Status = field.NewString(table, "status")
h.fillFieldMap()
return h
}
func (h *healthcheckTcpHistory) WithContext(ctx context.Context) IHealthcheckTcpHistoryDo {
return h.healthcheckTcpHistoryDo.WithContext(ctx)
}
func (h healthcheckTcpHistory) TableName() string { return h.healthcheckTcpHistoryDo.TableName() }
func (h healthcheckTcpHistory) Alias() string { return h.healthcheckTcpHistoryDo.Alias() }
func (h healthcheckTcpHistory) Columns(cols ...field.Expr) gen.Columns {
return h.healthcheckTcpHistoryDo.Columns(cols...)
}
func (h *healthcheckTcpHistory) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := h.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (h *healthcheckTcpHistory) fillFieldMap() {
h.fieldMap = make(map[string]field.Expr, 6)
h.fieldMap["id"] = h.ID
h.fieldMap["created_at"] = h.CreatedAt
h.fieldMap["updated_at"] = h.UpdatedAt
h.fieldMap["deleted_at"] = h.DeletedAt
h.fieldMap["status"] = h.Status
}
func (h healthcheckTcpHistory) clone(db *gorm.DB) healthcheckTcpHistory {
h.healthcheckTcpHistoryDo.ReplaceConnPool(db.Statement.ConnPool)
return h
}
func (h healthcheckTcpHistory) replaceDB(db *gorm.DB) healthcheckTcpHistory {
h.healthcheckTcpHistoryDo.ReplaceDB(db)
return h
}
type healthcheckTcpHistoryHasOneHealthcheckTCP struct {
db *gorm.DB
field.RelationField
}
func (a healthcheckTcpHistoryHasOneHealthcheckTCP) Where(conds ...field.Expr) *healthcheckTcpHistoryHasOneHealthcheckTCP {
if len(conds) == 0 {
return &a
}
exprs := make([]clause.Expression, 0, len(conds))
for _, cond := range conds {
exprs = append(exprs, cond.BeCond().(clause.Expression))
}
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
return &a
}
func (a healthcheckTcpHistoryHasOneHealthcheckTCP) WithContext(ctx context.Context) *healthcheckTcpHistoryHasOneHealthcheckTCP {
a.db = a.db.WithContext(ctx)
return &a
}
func (a healthcheckTcpHistoryHasOneHealthcheckTCP) Session(session *gorm.Session) *healthcheckTcpHistoryHasOneHealthcheckTCP {
a.db = a.db.Session(session)
return &a
}
func (a healthcheckTcpHistoryHasOneHealthcheckTCP) Model(m *models.HealthcheckTcpHistory) *healthcheckTcpHistoryHasOneHealthcheckTCPTx {
return &healthcheckTcpHistoryHasOneHealthcheckTCPTx{a.db.Model(m).Association(a.Name())}
}
type healthcheckTcpHistoryHasOneHealthcheckTCPTx struct{ tx *gorm.Association }
func (a healthcheckTcpHistoryHasOneHealthcheckTCPTx) Find() (result *models.HealthcheckTcp, err error) {
return result, a.tx.Find(&result)
}
func (a healthcheckTcpHistoryHasOneHealthcheckTCPTx) Append(values ...*models.HealthcheckTcp) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Append(targetValues...)
}
func (a healthcheckTcpHistoryHasOneHealthcheckTCPTx) Replace(values ...*models.HealthcheckTcp) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Replace(targetValues...)
}
func (a healthcheckTcpHistoryHasOneHealthcheckTCPTx) Delete(values ...*models.HealthcheckTcp) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Delete(targetValues...)
}
func (a healthcheckTcpHistoryHasOneHealthcheckTCPTx) Clear() error {
return a.tx.Clear()
}
func (a healthcheckTcpHistoryHasOneHealthcheckTCPTx) Count() int64 {
return a.tx.Count()
}
type healthcheckTcpHistoryDo struct{ gen.DO }
type IHealthcheckTcpHistoryDo interface {
gen.SubQuery
Debug() IHealthcheckTcpHistoryDo
WithContext(ctx context.Context) IHealthcheckTcpHistoryDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IHealthcheckTcpHistoryDo
WriteDB() IHealthcheckTcpHistoryDo
As(alias string) gen.Dao
Session(config *gorm.Session) IHealthcheckTcpHistoryDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IHealthcheckTcpHistoryDo
Not(conds ...gen.Condition) IHealthcheckTcpHistoryDo
Or(conds ...gen.Condition) IHealthcheckTcpHistoryDo
Select(conds ...field.Expr) IHealthcheckTcpHistoryDo
Where(conds ...gen.Condition) IHealthcheckTcpHistoryDo
Order(conds ...field.Expr) IHealthcheckTcpHistoryDo
Distinct(cols ...field.Expr) IHealthcheckTcpHistoryDo
Omit(cols ...field.Expr) IHealthcheckTcpHistoryDo
Join(table schema.Tabler, on ...field.Expr) IHealthcheckTcpHistoryDo
LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTcpHistoryDo
RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTcpHistoryDo
Group(cols ...field.Expr) IHealthcheckTcpHistoryDo
Having(conds ...gen.Condition) IHealthcheckTcpHistoryDo
Limit(limit int) IHealthcheckTcpHistoryDo
Offset(offset int) IHealthcheckTcpHistoryDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckTcpHistoryDo
Unscoped() IHealthcheckTcpHistoryDo
Create(values ...*models.HealthcheckTcpHistory) error
CreateInBatches(values []*models.HealthcheckTcpHistory, batchSize int) error
Save(values ...*models.HealthcheckTcpHistory) error
First() (*models.HealthcheckTcpHistory, error)
Take() (*models.HealthcheckTcpHistory, error)
Last() (*models.HealthcheckTcpHistory, error)
Find() ([]*models.HealthcheckTcpHistory, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckTcpHistory, err error)
FindInBatches(result *[]*models.HealthcheckTcpHistory, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*models.HealthcheckTcpHistory) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) IHealthcheckTcpHistoryDo
Assign(attrs ...field.AssignExpr) IHealthcheckTcpHistoryDo
Joins(fields ...field.RelationField) IHealthcheckTcpHistoryDo
Preload(fields ...field.RelationField) IHealthcheckTcpHistoryDo
FirstOrInit() (*models.HealthcheckTcpHistory, error)
FirstOrCreate() (*models.HealthcheckTcpHistory, error)
FindByPage(offset int, limit int) (result []*models.HealthcheckTcpHistory, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) IHealthcheckTcpHistoryDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (h healthcheckTcpHistoryDo) Debug() IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Debug())
}
func (h healthcheckTcpHistoryDo) WithContext(ctx context.Context) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.WithContext(ctx))
}
func (h healthcheckTcpHistoryDo) ReadDB() IHealthcheckTcpHistoryDo {
return h.Clauses(dbresolver.Read)
}
func (h healthcheckTcpHistoryDo) WriteDB() IHealthcheckTcpHistoryDo {
return h.Clauses(dbresolver.Write)
}
func (h healthcheckTcpHistoryDo) Session(config *gorm.Session) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Session(config))
}
func (h healthcheckTcpHistoryDo) Clauses(conds ...clause.Expression) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Clauses(conds...))
}
func (h healthcheckTcpHistoryDo) Returning(value interface{}, columns ...string) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Returning(value, columns...))
}
func (h healthcheckTcpHistoryDo) Not(conds ...gen.Condition) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Not(conds...))
}
func (h healthcheckTcpHistoryDo) Or(conds ...gen.Condition) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Or(conds...))
}
func (h healthcheckTcpHistoryDo) Select(conds ...field.Expr) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Select(conds...))
}
func (h healthcheckTcpHistoryDo) Where(conds ...gen.Condition) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Where(conds...))
}
func (h healthcheckTcpHistoryDo) Order(conds ...field.Expr) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Order(conds...))
}
func (h healthcheckTcpHistoryDo) Distinct(cols ...field.Expr) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Distinct(cols...))
}
func (h healthcheckTcpHistoryDo) Omit(cols ...field.Expr) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Omit(cols...))
}
func (h healthcheckTcpHistoryDo) Join(table schema.Tabler, on ...field.Expr) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Join(table, on...))
}
func (h healthcheckTcpHistoryDo) LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.LeftJoin(table, on...))
}
func (h healthcheckTcpHistoryDo) RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.RightJoin(table, on...))
}
func (h healthcheckTcpHistoryDo) Group(cols ...field.Expr) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Group(cols...))
}
func (h healthcheckTcpHistoryDo) Having(conds ...gen.Condition) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Having(conds...))
}
func (h healthcheckTcpHistoryDo) Limit(limit int) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Limit(limit))
}
func (h healthcheckTcpHistoryDo) Offset(offset int) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Offset(offset))
}
func (h healthcheckTcpHistoryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Scopes(funcs...))
}
func (h healthcheckTcpHistoryDo) Unscoped() IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Unscoped())
}
func (h healthcheckTcpHistoryDo) Create(values ...*models.HealthcheckTcpHistory) error {
if len(values) == 0 {
return nil
}
return h.DO.Create(values)
}
func (h healthcheckTcpHistoryDo) CreateInBatches(values []*models.HealthcheckTcpHistory, batchSize int) error {
return h.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (h healthcheckTcpHistoryDo) Save(values ...*models.HealthcheckTcpHistory) error {
if len(values) == 0 {
return nil
}
return h.DO.Save(values)
}
func (h healthcheckTcpHistoryDo) First() (*models.HealthcheckTcpHistory, error) {
if result, err := h.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckTcpHistory), nil
}
}
func (h healthcheckTcpHistoryDo) Take() (*models.HealthcheckTcpHistory, error) {
if result, err := h.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckTcpHistory), nil
}
}
func (h healthcheckTcpHistoryDo) Last() (*models.HealthcheckTcpHistory, error) {
if result, err := h.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckTcpHistory), nil
}
}
func (h healthcheckTcpHistoryDo) Find() ([]*models.HealthcheckTcpHistory, error) {
result, err := h.DO.Find()
return result.([]*models.HealthcheckTcpHistory), err
}
func (h healthcheckTcpHistoryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckTcpHistory, err error) {
buf := make([]*models.HealthcheckTcpHistory, 0, batchSize)
err = h.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (h healthcheckTcpHistoryDo) FindInBatches(result *[]*models.HealthcheckTcpHistory, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return h.DO.FindInBatches(result, batchSize, fc)
}
func (h healthcheckTcpHistoryDo) Attrs(attrs ...field.AssignExpr) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Attrs(attrs...))
}
func (h healthcheckTcpHistoryDo) Assign(attrs ...field.AssignExpr) IHealthcheckTcpHistoryDo {
return h.withDO(h.DO.Assign(attrs...))
}
func (h healthcheckTcpHistoryDo) Joins(fields ...field.RelationField) IHealthcheckTcpHistoryDo {
for _, _f := range fields {
h = *h.withDO(h.DO.Joins(_f))
}
return &h
}
func (h healthcheckTcpHistoryDo) Preload(fields ...field.RelationField) IHealthcheckTcpHistoryDo {
for _, _f := range fields {
h = *h.withDO(h.DO.Preload(_f))
}
return &h
}
func (h healthcheckTcpHistoryDo) FirstOrInit() (*models.HealthcheckTcpHistory, error) {
if result, err := h.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckTcpHistory), nil
}
}
func (h healthcheckTcpHistoryDo) FirstOrCreate() (*models.HealthcheckTcpHistory, error) {
if result, err := h.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckTcpHistory), nil
}
}
func (h healthcheckTcpHistoryDo) FindByPage(offset int, limit int) (result []*models.HealthcheckTcpHistory, count int64, err error) {
result, err = h.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = h.Offset(-1).Limit(-1).Count()
return
}
func (h healthcheckTcpHistoryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = h.Count()
if err != nil {
return
}
err = h.Offset(offset).Limit(limit).Scan(result)
return
}
func (h healthcheckTcpHistoryDo) Scan(result interface{}) (err error) {
return h.DO.Scan(result)
}
func (h healthcheckTcpHistoryDo) Delete(models ...*models.HealthcheckTcpHistory) (result gen.ResultInfo, err error) {
return h.DO.Delete(models)
}
func (h *healthcheckTcpHistoryDo) withDO(do gen.Dao) *healthcheckTcpHistoryDo {
h.DO = *do.(*gen.DO)
return h
}

View file

@ -19,32 +19,32 @@ import (
"code.tjo.space/mentos1386/zdravko/internal/models"
)
func newHealthcheckTCP(db *gorm.DB, opts ...gen.DOOption) healthcheckTCP {
_healthcheckTCP := healthcheckTCP{}
func newHealthcheckTcp(db *gorm.DB, opts ...gen.DOOption) healthcheckTcp {
_healthcheckTcp := healthcheckTcp{}
_healthcheckTCP.healthcheckTCPDo.UseDB(db, opts...)
_healthcheckTCP.healthcheckTCPDo.UseModel(&models.HealthcheckTCP{})
_healthcheckTcp.healthcheckTcpDo.UseDB(db, opts...)
_healthcheckTcp.healthcheckTcpDo.UseModel(&models.HealthcheckTcp{})
tableName := _healthcheckTCP.healthcheckTCPDo.TableName()
_healthcheckTCP.ALL = field.NewAsterisk(tableName)
_healthcheckTCP.ID = field.NewUint(tableName, "id")
_healthcheckTCP.CreatedAt = field.NewTime(tableName, "created_at")
_healthcheckTCP.UpdatedAt = field.NewTime(tableName, "updated_at")
_healthcheckTCP.DeletedAt = field.NewField(tableName, "deleted_at")
_healthcheckTCP.Name = field.NewString(tableName, "name")
_healthcheckTCP.Status = field.NewString(tableName, "status")
_healthcheckTCP.UptimePercentage = field.NewFloat64(tableName, "uptime_percentage")
_healthcheckTCP.Schedule = field.NewString(tableName, "schedule")
_healthcheckTCP.Hostname = field.NewString(tableName, "hostname")
_healthcheckTCP.Port = field.NewInt(tableName, "port")
tableName := _healthcheckTcp.healthcheckTcpDo.TableName()
_healthcheckTcp.ALL = field.NewAsterisk(tableName)
_healthcheckTcp.ID = field.NewUint(tableName, "id")
_healthcheckTcp.CreatedAt = field.NewTime(tableName, "created_at")
_healthcheckTcp.UpdatedAt = field.NewTime(tableName, "updated_at")
_healthcheckTcp.DeletedAt = field.NewField(tableName, "deleted_at")
_healthcheckTcp.Name = field.NewString(tableName, "name")
_healthcheckTcp.Status = field.NewString(tableName, "status")
_healthcheckTcp.UptimePercentage = field.NewFloat64(tableName, "uptime_percentage")
_healthcheckTcp.Schedule = field.NewString(tableName, "schedule")
_healthcheckTcp.Hostname = field.NewString(tableName, "hostname")
_healthcheckTcp.Port = field.NewInt(tableName, "port")
_healthcheckTCP.fillFieldMap()
_healthcheckTcp.fillFieldMap()
return _healthcheckTCP
return _healthcheckTcp
}
type healthcheckTCP struct {
healthcheckTCPDo healthcheckTCPDo
type healthcheckTcp struct {
healthcheckTcpDo healthcheckTcpDo
ALL field.Asterisk
ID field.Uint
@ -61,17 +61,17 @@ type healthcheckTCP struct {
fieldMap map[string]field.Expr
}
func (h healthcheckTCP) Table(newTableName string) *healthcheckTCP {
h.healthcheckTCPDo.UseTable(newTableName)
func (h healthcheckTcp) Table(newTableName string) *healthcheckTcp {
h.healthcheckTcpDo.UseTable(newTableName)
return h.updateTableName(newTableName)
}
func (h healthcheckTCP) As(alias string) *healthcheckTCP {
h.healthcheckTCPDo.DO = *(h.healthcheckTCPDo.As(alias).(*gen.DO))
func (h healthcheckTcp) As(alias string) *healthcheckTcp {
h.healthcheckTcpDo.DO = *(h.healthcheckTcpDo.As(alias).(*gen.DO))
return h.updateTableName(alias)
}
func (h *healthcheckTCP) updateTableName(table string) *healthcheckTCP {
func (h *healthcheckTcp) updateTableName(table string) *healthcheckTcp {
h.ALL = field.NewAsterisk(table)
h.ID = field.NewUint(table, "id")
h.CreatedAt = field.NewTime(table, "created_at")
@ -89,19 +89,19 @@ func (h *healthcheckTCP) updateTableName(table string) *healthcheckTCP {
return h
}
func (h *healthcheckTCP) WithContext(ctx context.Context) IHealthcheckTCPDo {
return h.healthcheckTCPDo.WithContext(ctx)
func (h *healthcheckTcp) WithContext(ctx context.Context) IHealthcheckTcpDo {
return h.healthcheckTcpDo.WithContext(ctx)
}
func (h healthcheckTCP) TableName() string { return h.healthcheckTCPDo.TableName() }
func (h healthcheckTcp) TableName() string { return h.healthcheckTcpDo.TableName() }
func (h healthcheckTCP) Alias() string { return h.healthcheckTCPDo.Alias() }
func (h healthcheckTcp) Alias() string { return h.healthcheckTcpDo.Alias() }
func (h healthcheckTCP) Columns(cols ...field.Expr) gen.Columns {
return h.healthcheckTCPDo.Columns(cols...)
func (h healthcheckTcp) Columns(cols ...field.Expr) gen.Columns {
return h.healthcheckTcpDo.Columns(cols...)
}
func (h *healthcheckTCP) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
func (h *healthcheckTcp) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := h.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
@ -110,7 +110,7 @@ func (h *healthcheckTCP) GetFieldByName(fieldName string) (field.OrderExpr, bool
return _oe, ok
}
func (h *healthcheckTCP) fillFieldMap() {
func (h *healthcheckTcp) fillFieldMap() {
h.fieldMap = make(map[string]field.Expr, 10)
h.fieldMap["id"] = h.ID
h.fieldMap["created_at"] = h.CreatedAt
@ -124,58 +124,58 @@ func (h *healthcheckTCP) fillFieldMap() {
h.fieldMap["port"] = h.Port
}
func (h healthcheckTCP) clone(db *gorm.DB) healthcheckTCP {
h.healthcheckTCPDo.ReplaceConnPool(db.Statement.ConnPool)
func (h healthcheckTcp) clone(db *gorm.DB) healthcheckTcp {
h.healthcheckTcpDo.ReplaceConnPool(db.Statement.ConnPool)
return h
}
func (h healthcheckTCP) replaceDB(db *gorm.DB) healthcheckTCP {
h.healthcheckTCPDo.ReplaceDB(db)
func (h healthcheckTcp) replaceDB(db *gorm.DB) healthcheckTcp {
h.healthcheckTcpDo.ReplaceDB(db)
return h
}
type healthcheckTCPDo struct{ gen.DO }
type healthcheckTcpDo struct{ gen.DO }
type IHealthcheckTCPDo interface {
type IHealthcheckTcpDo interface {
gen.SubQuery
Debug() IHealthcheckTCPDo
WithContext(ctx context.Context) IHealthcheckTCPDo
Debug() IHealthcheckTcpDo
WithContext(ctx context.Context) IHealthcheckTcpDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IHealthcheckTCPDo
WriteDB() IHealthcheckTCPDo
ReadDB() IHealthcheckTcpDo
WriteDB() IHealthcheckTcpDo
As(alias string) gen.Dao
Session(config *gorm.Session) IHealthcheckTCPDo
Session(config *gorm.Session) IHealthcheckTcpDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IHealthcheckTCPDo
Not(conds ...gen.Condition) IHealthcheckTCPDo
Or(conds ...gen.Condition) IHealthcheckTCPDo
Select(conds ...field.Expr) IHealthcheckTCPDo
Where(conds ...gen.Condition) IHealthcheckTCPDo
Order(conds ...field.Expr) IHealthcheckTCPDo
Distinct(cols ...field.Expr) IHealthcheckTCPDo
Omit(cols ...field.Expr) IHealthcheckTCPDo
Join(table schema.Tabler, on ...field.Expr) IHealthcheckTCPDo
LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTCPDo
RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTCPDo
Group(cols ...field.Expr) IHealthcheckTCPDo
Having(conds ...gen.Condition) IHealthcheckTCPDo
Limit(limit int) IHealthcheckTCPDo
Offset(offset int) IHealthcheckTCPDo
Clauses(conds ...clause.Expression) IHealthcheckTcpDo
Not(conds ...gen.Condition) IHealthcheckTcpDo
Or(conds ...gen.Condition) IHealthcheckTcpDo
Select(conds ...field.Expr) IHealthcheckTcpDo
Where(conds ...gen.Condition) IHealthcheckTcpDo
Order(conds ...field.Expr) IHealthcheckTcpDo
Distinct(cols ...field.Expr) IHealthcheckTcpDo
Omit(cols ...field.Expr) IHealthcheckTcpDo
Join(table schema.Tabler, on ...field.Expr) IHealthcheckTcpDo
LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTcpDo
RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTcpDo
Group(cols ...field.Expr) IHealthcheckTcpDo
Having(conds ...gen.Condition) IHealthcheckTcpDo
Limit(limit int) IHealthcheckTcpDo
Offset(offset int) IHealthcheckTcpDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckTCPDo
Unscoped() IHealthcheckTCPDo
Create(values ...*models.HealthcheckTCP) error
CreateInBatches(values []*models.HealthcheckTCP, batchSize int) error
Save(values ...*models.HealthcheckTCP) error
First() (*models.HealthcheckTCP, error)
Take() (*models.HealthcheckTCP, error)
Last() (*models.HealthcheckTCP, error)
Find() ([]*models.HealthcheckTCP, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckTCP, err error)
FindInBatches(result *[]*models.HealthcheckTCP, batchSize int, fc func(tx gen.Dao, batch int) error) error
Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckTcpDo
Unscoped() IHealthcheckTcpDo
Create(values ...*models.HealthcheckTcp) error
CreateInBatches(values []*models.HealthcheckTcp, batchSize int) error
Save(values ...*models.HealthcheckTcp) error
First() (*models.HealthcheckTcp, error)
Take() (*models.HealthcheckTcp, error)
Last() (*models.HealthcheckTcp, error)
Find() ([]*models.HealthcheckTcp, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckTcp, err error)
FindInBatches(result *[]*models.HealthcheckTcp, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*models.HealthcheckTCP) (info gen.ResultInfo, err error)
Delete(...*models.HealthcheckTcp) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
@ -183,163 +183,163 @@ type IHealthcheckTCPDo interface {
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) IHealthcheckTCPDo
Assign(attrs ...field.AssignExpr) IHealthcheckTCPDo
Joins(fields ...field.RelationField) IHealthcheckTCPDo
Preload(fields ...field.RelationField) IHealthcheckTCPDo
FirstOrInit() (*models.HealthcheckTCP, error)
FirstOrCreate() (*models.HealthcheckTCP, error)
FindByPage(offset int, limit int) (result []*models.HealthcheckTCP, count int64, err error)
Attrs(attrs ...field.AssignExpr) IHealthcheckTcpDo
Assign(attrs ...field.AssignExpr) IHealthcheckTcpDo
Joins(fields ...field.RelationField) IHealthcheckTcpDo
Preload(fields ...field.RelationField) IHealthcheckTcpDo
FirstOrInit() (*models.HealthcheckTcp, error)
FirstOrCreate() (*models.HealthcheckTcp, error)
FindByPage(offset int, limit int) (result []*models.HealthcheckTcp, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) IHealthcheckTCPDo
Returning(value interface{}, columns ...string) IHealthcheckTcpDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (h healthcheckTCPDo) Debug() IHealthcheckTCPDo {
func (h healthcheckTcpDo) Debug() IHealthcheckTcpDo {
return h.withDO(h.DO.Debug())
}
func (h healthcheckTCPDo) WithContext(ctx context.Context) IHealthcheckTCPDo {
func (h healthcheckTcpDo) WithContext(ctx context.Context) IHealthcheckTcpDo {
return h.withDO(h.DO.WithContext(ctx))
}
func (h healthcheckTCPDo) ReadDB() IHealthcheckTCPDo {
func (h healthcheckTcpDo) ReadDB() IHealthcheckTcpDo {
return h.Clauses(dbresolver.Read)
}
func (h healthcheckTCPDo) WriteDB() IHealthcheckTCPDo {
func (h healthcheckTcpDo) WriteDB() IHealthcheckTcpDo {
return h.Clauses(dbresolver.Write)
}
func (h healthcheckTCPDo) Session(config *gorm.Session) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Session(config *gorm.Session) IHealthcheckTcpDo {
return h.withDO(h.DO.Session(config))
}
func (h healthcheckTCPDo) Clauses(conds ...clause.Expression) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Clauses(conds ...clause.Expression) IHealthcheckTcpDo {
return h.withDO(h.DO.Clauses(conds...))
}
func (h healthcheckTCPDo) Returning(value interface{}, columns ...string) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Returning(value interface{}, columns ...string) IHealthcheckTcpDo {
return h.withDO(h.DO.Returning(value, columns...))
}
func (h healthcheckTCPDo) Not(conds ...gen.Condition) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Not(conds ...gen.Condition) IHealthcheckTcpDo {
return h.withDO(h.DO.Not(conds...))
}
func (h healthcheckTCPDo) Or(conds ...gen.Condition) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Or(conds ...gen.Condition) IHealthcheckTcpDo {
return h.withDO(h.DO.Or(conds...))
}
func (h healthcheckTCPDo) Select(conds ...field.Expr) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Select(conds ...field.Expr) IHealthcheckTcpDo {
return h.withDO(h.DO.Select(conds...))
}
func (h healthcheckTCPDo) Where(conds ...gen.Condition) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Where(conds ...gen.Condition) IHealthcheckTcpDo {
return h.withDO(h.DO.Where(conds...))
}
func (h healthcheckTCPDo) Order(conds ...field.Expr) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Order(conds ...field.Expr) IHealthcheckTcpDo {
return h.withDO(h.DO.Order(conds...))
}
func (h healthcheckTCPDo) Distinct(cols ...field.Expr) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Distinct(cols ...field.Expr) IHealthcheckTcpDo {
return h.withDO(h.DO.Distinct(cols...))
}
func (h healthcheckTCPDo) Omit(cols ...field.Expr) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Omit(cols ...field.Expr) IHealthcheckTcpDo {
return h.withDO(h.DO.Omit(cols...))
}
func (h healthcheckTCPDo) Join(table schema.Tabler, on ...field.Expr) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Join(table schema.Tabler, on ...field.Expr) IHealthcheckTcpDo {
return h.withDO(h.DO.Join(table, on...))
}
func (h healthcheckTCPDo) LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTCPDo {
func (h healthcheckTcpDo) LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTcpDo {
return h.withDO(h.DO.LeftJoin(table, on...))
}
func (h healthcheckTCPDo) RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTCPDo {
func (h healthcheckTcpDo) RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckTcpDo {
return h.withDO(h.DO.RightJoin(table, on...))
}
func (h healthcheckTCPDo) Group(cols ...field.Expr) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Group(cols ...field.Expr) IHealthcheckTcpDo {
return h.withDO(h.DO.Group(cols...))
}
func (h healthcheckTCPDo) Having(conds ...gen.Condition) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Having(conds ...gen.Condition) IHealthcheckTcpDo {
return h.withDO(h.DO.Having(conds...))
}
func (h healthcheckTCPDo) Limit(limit int) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Limit(limit int) IHealthcheckTcpDo {
return h.withDO(h.DO.Limit(limit))
}
func (h healthcheckTCPDo) Offset(offset int) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Offset(offset int) IHealthcheckTcpDo {
return h.withDO(h.DO.Offset(offset))
}
func (h healthcheckTCPDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckTcpDo {
return h.withDO(h.DO.Scopes(funcs...))
}
func (h healthcheckTCPDo) Unscoped() IHealthcheckTCPDo {
func (h healthcheckTcpDo) Unscoped() IHealthcheckTcpDo {
return h.withDO(h.DO.Unscoped())
}
func (h healthcheckTCPDo) Create(values ...*models.HealthcheckTCP) error {
func (h healthcheckTcpDo) Create(values ...*models.HealthcheckTcp) error {
if len(values) == 0 {
return nil
}
return h.DO.Create(values)
}
func (h healthcheckTCPDo) CreateInBatches(values []*models.HealthcheckTCP, batchSize int) error {
func (h healthcheckTcpDo) CreateInBatches(values []*models.HealthcheckTcp, batchSize int) error {
return h.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (h healthcheckTCPDo) Save(values ...*models.HealthcheckTCP) error {
func (h healthcheckTcpDo) Save(values ...*models.HealthcheckTcp) error {
if len(values) == 0 {
return nil
}
return h.DO.Save(values)
}
func (h healthcheckTCPDo) First() (*models.HealthcheckTCP, error) {
func (h healthcheckTcpDo) First() (*models.HealthcheckTcp, error) {
if result, err := h.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckTCP), nil
return result.(*models.HealthcheckTcp), nil
}
}
func (h healthcheckTCPDo) Take() (*models.HealthcheckTCP, error) {
func (h healthcheckTcpDo) Take() (*models.HealthcheckTcp, error) {
if result, err := h.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckTCP), nil
return result.(*models.HealthcheckTcp), nil
}
}
func (h healthcheckTCPDo) Last() (*models.HealthcheckTCP, error) {
func (h healthcheckTcpDo) Last() (*models.HealthcheckTcp, error) {
if result, err := h.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckTCP), nil
return result.(*models.HealthcheckTcp), nil
}
}
func (h healthcheckTCPDo) Find() ([]*models.HealthcheckTCP, error) {
func (h healthcheckTcpDo) Find() ([]*models.HealthcheckTcp, error) {
result, err := h.DO.Find()
return result.([]*models.HealthcheckTCP), err
return result.([]*models.HealthcheckTcp), err
}
func (h healthcheckTCPDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckTCP, err error) {
buf := make([]*models.HealthcheckTCP, 0, batchSize)
func (h healthcheckTcpDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.HealthcheckTcp, err error) {
buf := make([]*models.HealthcheckTcp, 0, batchSize)
err = h.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
@ -347,49 +347,49 @@ func (h healthcheckTCPDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch i
return results, err
}
func (h healthcheckTCPDo) FindInBatches(result *[]*models.HealthcheckTCP, batchSize int, fc func(tx gen.Dao, batch int) error) error {
func (h healthcheckTcpDo) FindInBatches(result *[]*models.HealthcheckTcp, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return h.DO.FindInBatches(result, batchSize, fc)
}
func (h healthcheckTCPDo) Attrs(attrs ...field.AssignExpr) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Attrs(attrs ...field.AssignExpr) IHealthcheckTcpDo {
return h.withDO(h.DO.Attrs(attrs...))
}
func (h healthcheckTCPDo) Assign(attrs ...field.AssignExpr) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Assign(attrs ...field.AssignExpr) IHealthcheckTcpDo {
return h.withDO(h.DO.Assign(attrs...))
}
func (h healthcheckTCPDo) Joins(fields ...field.RelationField) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Joins(fields ...field.RelationField) IHealthcheckTcpDo {
for _, _f := range fields {
h = *h.withDO(h.DO.Joins(_f))
}
return &h
}
func (h healthcheckTCPDo) Preload(fields ...field.RelationField) IHealthcheckTCPDo {
func (h healthcheckTcpDo) Preload(fields ...field.RelationField) IHealthcheckTcpDo {
for _, _f := range fields {
h = *h.withDO(h.DO.Preload(_f))
}
return &h
}
func (h healthcheckTCPDo) FirstOrInit() (*models.HealthcheckTCP, error) {
func (h healthcheckTcpDo) FirstOrInit() (*models.HealthcheckTcp, error) {
if result, err := h.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckTCP), nil
return result.(*models.HealthcheckTcp), nil
}
}
func (h healthcheckTCPDo) FirstOrCreate() (*models.HealthcheckTCP, error) {
func (h healthcheckTcpDo) FirstOrCreate() (*models.HealthcheckTcp, error) {
if result, err := h.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckTCP), nil
return result.(*models.HealthcheckTcp), nil
}
}
func (h healthcheckTCPDo) FindByPage(offset int, limit int) (result []*models.HealthcheckTCP, count int64, err error) {
func (h healthcheckTcpDo) FindByPage(offset int, limit int) (result []*models.HealthcheckTcp, count int64, err error) {
result, err = h.Offset(offset).Limit(limit).Find()
if err != nil {
return
@ -404,7 +404,7 @@ func (h healthcheckTCPDo) FindByPage(offset int, limit int) (result []*models.He
return
}
func (h healthcheckTCPDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
func (h healthcheckTcpDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = h.Count()
if err != nil {
return
@ -414,15 +414,15 @@ func (h healthcheckTCPDo) ScanByPage(result interface{}, offset int, limit int)
return
}
func (h healthcheckTCPDo) Scan(result interface{}) (err error) {
func (h healthcheckTcpDo) Scan(result interface{}) (err error) {
return h.DO.Scan(result)
}
func (h healthcheckTCPDo) Delete(models ...*models.HealthcheckTCP) (result gen.ResultInfo, err error) {
func (h healthcheckTcpDo) Delete(models ...*models.HealthcheckTcp) (result gen.ResultInfo, err error) {
return h.DO.Delete(models)
}
func (h *healthcheckTCPDo) withDO(do gen.Dao) *healthcheckTCPDo {
func (h *healthcheckTcpDo) withDO(do gen.Dao) *healthcheckTcpDo {
h.DO = *do.(*gen.DO)
return h
}

View file

@ -0,0 +1,45 @@
package services
import (
"context"
"log"
"code.tjo.space/mentos1386/zdravko/internal/models"
"code.tjo.space/mentos1386/zdravko/internal/models/query"
"code.tjo.space/mentos1386/zdravko/internal/workflows"
"go.temporal.io/sdk/client"
"gorm.io/gorm"
)
func CreateHealthcheckHttp(ctx context.Context, db *gorm.DB, healthcheck *models.HealthcheckHttp) error {
return db.WithContext(ctx).Create(healthcheck).Error
}
func GetHealthcheckHttp(ctx context.Context, q *query.Query, id uint) (*models.HealthcheckHttp, error) {
log.Println("GetHealthcheckHttp")
return q.HealthcheckHttp.WithContext(ctx).Where(
q.HealthcheckHttp.ID.Eq(id),
).First()
}
func StartHealthcheckHttp(ctx context.Context, t client.Client) error {
log.Println("Starting HealthcheckHttp Workflow")
args := make([]interface{}, 0)
args = append(args, workflows.HealthcheckHttpWorkflowParam{Id: 1})
_, err := t.ScheduleClient().Create(ctx, client.ScheduleOptions{
ID: "healthcheck-http-id",
Spec: client.ScheduleSpec{
CronExpressions: []string{"0 * * * *"},
},
Action: &client.ScheduleWorkflowAction{
ID: "healthcheck-http-id-workflow",
Workflow: workflows.HealthcheckHttpWorkflowDefinition,
Args: args,
TaskQueue: "default",
},
})
return err
}

14
internal/temporal.go Normal file
View file

@ -0,0 +1,14 @@
package internal
import (
"code.tjo.space/mentos1386/zdravko/internal/config"
"go.temporal.io/sdk/client"
)
func ConnectToTemporal(cfg *config.Config) (client.Client, error) {
c, err := client.Dial(client.Options{HostPort: cfg.Temporal.ServerHost})
if err != nil {
return nil, err
}
return c, nil
}

View file

@ -0,0 +1,29 @@
package workflows
import (
"time"
"code.tjo.space/mentos1386/zdravko/internal/activities"
"go.temporal.io/sdk/workflow"
)
type HealthcheckHttpWorkflowParam struct {
Id uint
}
func HealthcheckHttpWorkflowDefinition(ctx workflow.Context, param HealthcheckHttpWorkflowParam) error {
options := workflow.ActivityOptions{
StartToCloseTimeout: 10 * time.Second,
}
ctx = workflow.WithActivityOptions(ctx, options)
activityParam := activities.HealtcheckHttpActivityParam{
Url: "https://google.com",
Method: "GET",
}
var result *activities.HealthcheckHttpActivityResult
err := workflow.ExecuteActivity(ctx, activities.HealthcheckHttpActivityDefinition, activityParam).Get(ctx, &result)
return err
}

View file

@ -14,6 +14,6 @@ processes:
availability:
restart: "always"
temporal:
command: watchexec -r -e go,tmpl,css just run-temporal
command: just run-temporal
availability:
restart: "always"

View file

@ -28,7 +28,15 @@ func main() {
g.UseDB(db)
// Generate default DAO interface for those specified structs
g.ApplyBasic(models.HealthcheckHTTP{}, models.HealthcheckTCP{}, models.Cronjob{}, models.OAuth2State{})
g.ApplyBasic(
models.HealthcheckHttp{},
models.HealthcheckHttpHistory{},
models.HealthcheckTcp{},
models.HealthcheckTcpHistory{},
models.Cronjob{},
models.CronjobHistory{},
models.OAuth2State{},
)
// Execute the generator
g.Execute()

View file

@ -640,6 +640,10 @@ video {
margin-top: 5rem;
}
.mt-4 {
margin-top: 1rem;
}
.mt-8 {
margin-top: 2rem;
}
@ -756,12 +760,6 @@ video {
gap: 1px;
}
.space-x-1 > :not([hidden]) ~ :not([hidden]) {
--tw-space-x-reverse: 0;
margin-right: calc(0.25rem * var(--tw-space-x-reverse));
margin-left: calc(0.25rem * calc(1 - var(--tw-space-x-reverse)));
}
.space-y-4 > :not([hidden]) ~ :not([hidden]) {
--tw-space-y-reverse: 0;
margin-top: calc(1rem * calc(1 - var(--tw-space-y-reverse)));
@ -952,11 +950,6 @@ video {
line-height: 1.25rem;
}
.text-xl {
font-size: 1.25rem;
line-height: 1.75rem;
}
.text-xs {
font-size: 0.75rem;
line-height: 1rem;
@ -1278,12 +1271,6 @@ video {
}
@media (min-width: 768px) {
.md\:space-x-2 > :not([hidden]) ~ :not([hidden]) {
--tw-space-x-reverse: 0;
margin-right: calc(0.5rem * var(--tw-space-x-reverse));
margin-left: calc(0.5rem * calc(1 - var(--tw-space-x-reverse)));
}
.md\:text-3xl {
font-size: 1.875rem;
line-height: 2.25rem;
@ -1311,10 +1298,43 @@ video {
}
}
.rtl\:space-x-reverse:where([dir="rtl"], [dir="rtl"] *) > :not([hidden]) ~ :not([hidden]) {
--tw-space-x-reverse: 1;
}
.rtl\:text-right:where([dir="rtl"], [dir="rtl"] *) {
text-align: right;
}
@media (prefers-color-scheme: dark) {
.dark\:border-gray-600 {
--tw-border-opacity: 1;
border-color: rgb(75 85 99 / var(--tw-border-opacity));
}
.dark\:bg-gray-700 {
--tw-bg-opacity: 1;
background-color: rgb(55 65 81 / var(--tw-bg-opacity));
}
.dark\:text-white {
--tw-text-opacity: 1;
color: rgb(255 255 255 / var(--tw-text-opacity));
}
.dark\:placeholder-gray-400::-moz-placeholder {
--tw-placeholder-opacity: 1;
color: rgb(156 163 175 / var(--tw-placeholder-opacity));
}
.dark\:placeholder-gray-400::placeholder {
--tw-placeholder-opacity: 1;
color: rgb(156 163 175 / var(--tw-placeholder-opacity));
}
.dark\:focus\:border-blue-500:focus {
--tw-border-opacity: 1;
border-color: rgb(59 130 246 / var(--tw-border-opacity));
}
.dark\:focus\:ring-blue-500:focus {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(59 130 246 / var(--tw-ring-opacity));
}
}

View file

@ -22,7 +22,7 @@
</ul>
<div>
<nav class="breadcrumb" aria-label="Breadcrumb">
<ol class="inline-flex items-center space-x-1 md:space-x-2 rtl:space-x-reverse">
<ol class="inline-flex items-center">
{{ range .SettingsBreadcrumbs }}
<li class="inline-flex items-center">
<a href="{{ .Path }}" class="inline-flex items-center text-sm font-medium text-gray-700 hover:text-blue-600">

View file

@ -1,24 +1,30 @@
{{define "settings"}}
<h1 class="mb-4 text-xl font-bold text-gray-900">
Creating new Healthcheck.
</h1>
<form class="max-w-sm" action="/settings/healthchecks/create" method="post">
<div class="mb-5">
<label for="name" class="block mb-2 text-sm font-medium text-gray-900">Name</label>
<input type="name" name="name" id="name" placeholder="Github.com" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"/>
</div>
<div class="mb-5">
<label for="url" class="block mb-2 text-sm font-medium text-gray-900">Url</label>
<input type="url" name="url" id="url" placeholder="https://github.com" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"/>
</div>
<div class="mb-5">
<label for="method" class="block mb-2 text-sm font-medium text-gray-900">Method</label>
<input type="text" name="method" id="method" placeholder="GET" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"/>
</div>
<div class="mb-5">
<label for="schedule" class="block mb-2 text-sm font-medium text-gray-900">Schedule</label>
<input type="text" name="schedule" id="schedule" placeholder="* * * * *" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"/>
</div>
<button type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center">Create</button>
</form>
<section class="relative overflow-x-auto shadow-md sm:rounded-lg p-5 text-gray-500 bg-white">
<h1 class="text-lg font-semibold text-gray-900">
Creating new Healthcheck.
</h1>
<form class="max-w-sm mt-4" action="/settings/healthchecks/create" method="post">
<div class="mb-5">
<label for="name" class="block mb-2 text-sm font-medium text-gray-900">Name</label>
<input type="name" name="name" id="name" placeholder="Github.com" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"/>
</div>
<div class="mb-5">
<label for="schedule" class="block mb-2 text-sm font-medium text-gray-900">Schedule</label>
<input type="text" name="schedule" id="schedule" placeholder="* * * * *" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"/>
</div>
<div class="mb-5">
<label for="url" class="block mb-2 text-sm font-medium text-gray-900">Url</label>
<input type="url" name="url" id="url" placeholder="https://github.com" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"/>
</div>
<div class="mb-5">
<label for="method" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">HTTP Method</label>
<select id="method" name="method" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
<option>GET</option>
<option>POST</option>
<option>PUT</option>
</select>
</div>
<button type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center">Create</button>
</form>
</section>
{{end}}

View file

@ -1,8 +1,10 @@
{{define "settings"}}
<h1 class="mb-4 text-xl font-bold text-gray-900">
{{ .Healthcheck.Name }}
</h1>
{{ .Healthcheck.ID }}
{{ .Healthcheck.URL }}
{{ .Healthcheck.Schedule }}
<section class="relative overflow-x-auto shadow-md sm:rounded-lg p-5 text-gray-500 bg-white">
<h1 class="text-lg font-semibold text-gray-900">
{{ .Healthcheck.Name }}
</h1>
{{ .Healthcheck.ID }}
{{ .Healthcheck.URL }}
{{ .Healthcheck.Schedule }}
</section>
{{end}}