feat(healthcheck): abbility to add/list/get

This commit is contained in:
Tine 2024-02-15 23:47:56 +01:00
parent 6243cb28f3
commit 6db158ba96
Signed by: mentos1386
SSH key fingerprint: SHA256:MNtTsLbihYaWF8j1fkOHfkKNlnN1JQfxEU/rBU8nCGw
27 changed files with 1785 additions and 621 deletions

View file

@ -7,22 +7,23 @@ import (
"github.com/gorilla/mux"
"code.tjo.space/mentos1386/zdravko/internal"
"code.tjo.space/mentos1386/zdravko/internal/config"
"code.tjo.space/mentos1386/zdravko/internal/handlers"
"code.tjo.space/mentos1386/zdravko/web/static"
)
func main() {
config := internal.NewConfig()
cfg := config.NewConfig()
r := mux.NewRouter()
db, query, err := internal.ConnectToDatabase(config.DatabasePath)
db, query, err := internal.ConnectToDatabase(cfg.DatabasePath)
if err != nil {
log.Fatal(err)
}
log.Println("Connected to database")
h := handlers.NewBaseHandler(db, query, config)
h := handlers.NewBaseHandler(db, query, cfg)
// Health
r.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
@ -48,6 +49,9 @@ func main() {
// Authenticated routes
r.HandleFunc("/settings", h.Authenticated(h.SettingsOverviewGET)).Methods("GET")
r.HandleFunc("/settings/healthchecks", h.Authenticated(h.SettingsHealthchecksGET)).Methods("GET")
r.HandleFunc("/settings/healthchecks/create", h.Authenticated(h.SettingsHealthchecksCreateGET)).Methods("GET")
r.HandleFunc("/settings/healthchecks/create", h.Authenticated(h.SettingsHealthchecksCreatePOST)).Methods("POST")
r.HandleFunc("/settings/healthchecks/{id}", h.Authenticated(h.SettingsHealthchecksDescribeGET)).Methods("GET")
// OAuth2
r.HandleFunc("/oauth2/login", h.OAuth2LoginGET).Methods("GET")
@ -60,6 +64,6 @@ func main() {
// 404
r.PathPrefix("/").HandlerFunc(h.Error404).Methods("GET")
log.Println("Server started on", config.Port)
log.Fatal(http.ListenAndServe(":"+config.Port, r))
log.Println("Server started on", cfg.Port)
log.Fatal(http.ListenAndServe(":"+cfg.Port, r))
}

View file

@ -1,4 +1,4 @@
package internal
package config
import (
"fmt"
@ -99,7 +99,11 @@ func NewConfig() *Config {
err := viper.ReadInConfig()
if err != nil {
log.Fatalf("Error reading config file, %s", err)
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
// ignore
} else {
log.Fatalf("Error reading config file, %s", err)
}
}
log.Println("Config file used: ", viper.ConfigFileUsed())

View file

@ -14,7 +14,12 @@ func ConnectToDatabase(path string) (*gorm.DB, *query.Query, error) {
return nil, nil, err
}
err = db.AutoMigrate(&models.Healthcheck{}, &models.OAuth2State{})
err = db.AutoMigrate(
&models.HealthcheckHTTP{},
&models.HealthcheckTCP{},
&models.Cronjob{},
&models.OAuth2State{},
)
if err != nil {
return nil, nil, err
}

View file

@ -22,8 +22,8 @@ func (h *BaseHandler) Error404(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
err = ts.ExecuteTemplate(w, "base", &components.Base{
Page: nil,
Pages: Pages,
NavbarActive: nil,
Navbar: Pages,
})
if err != nil {
fmt.Println("Error", err)

View file

@ -1,7 +1,7 @@
package handlers
import (
"code.tjo.space/mentos1386/zdravko/internal"
"code.tjo.space/mentos1386/zdravko/internal/config"
"code.tjo.space/mentos1386/zdravko/internal/models/query"
"code.tjo.space/mentos1386/zdravko/web/templates/components"
"github.com/gorilla/sessions"
@ -9,9 +9,9 @@ import (
)
var Pages = []*components.Page{
{Path: "/", Title: "Status"},
{Path: "/incidents", Title: "Incidents"},
{Path: "/settings", Title: "Settings"},
{Path: "/", Title: "Status", Breadcrumb: "Status"},
{Path: "/incidents", Title: "Incidents", Breadcrumb: "Incidents"},
{Path: "/settings", Title: "Settings", Breadcrumb: "Settings"},
}
func GetPageByTitle(pages []*components.Page, title string) *components.Page {
@ -26,12 +26,12 @@ func GetPageByTitle(pages []*components.Page, title string) *components.Page {
type BaseHandler struct {
db *gorm.DB
query *query.Query
config *internal.Config
config *config.Config
store *sessions.CookieStore
}
func NewBaseHandler(db *gorm.DB, q *query.Query, config *internal.Config) *BaseHandler {
func NewBaseHandler(db *gorm.DB, q *query.Query, config *config.Config) *BaseHandler {
store := sessions.NewCookieStore([]byte(config.SessionSecret))
return &BaseHandler{db, q, config, store}

View file

@ -51,8 +51,8 @@ func (h *BaseHandler) Index(w http.ResponseWriter, r *http.Request) {
err = ts.ExecuteTemplate(w, "base", &IndexData{
Base: &components.Base{
Page: GetPageByTitle(Pages, "Status"),
Pages: Pages,
NavbarActive: GetPageByTitle(Pages, "Status"),
Navbar: Pages,
},
HealthChecks: []*HealthCheck{
newMockHealthCheck("example.com"),

View file

@ -10,7 +10,7 @@ import (
"net/http"
"time"
"code.tjo.space/mentos1386/zdravko/internal"
"code.tjo.space/mentos1386/zdravko/internal/config"
"code.tjo.space/mentos1386/zdravko/internal/models"
"golang.org/x/oauth2"
)
@ -29,7 +29,7 @@ func newRandomState() string {
return hex.EncodeToString(b)
}
func newOAuth2(config *internal.Config) *oauth2.Config {
func newOAuth2(config *config.Config) *oauth2.Config {
return &oauth2.Config{
ClientID: config.OAuth2.ClientID,
ClientSecret: config.OAuth2.ClientSecret,

View file

@ -10,18 +10,42 @@ import (
type Settings struct {
*components.Base
SettingsPage *components.Page
SettingsPages []*components.Page
User *AuthenticatedUser
SettingsSidebarActive *components.Page
SettingsSidebar []*components.Page
User *AuthenticatedUser
SettingsBreadcrumbs []*components.Page
}
func NewSettings(user *AuthenticatedUser, page *components.Page, breadCrumbs []*components.Page) *Settings {
return &Settings{
Base: &components.Base{
NavbarActive: GetPageByTitle(Pages, "Settings"),
Navbar: Pages,
},
SettingsSidebarActive: page,
SettingsSidebar: SettingsNavbar,
SettingsBreadcrumbs: breadCrumbs,
User: user,
}
}
var SettingsPages = []*components.Page{
{Path: "/settings", Title: "Overview"},
{Path: "/settings/healthchecks", Title: "Healthchecks"},
{Path: "/settings/cronjobs", Title: "CronJobs"},
{Path: "/settings/workers", Title: "Workers"},
{Path: "/temporal", Title: "Temporal"},
{Path: "/oauth2/logout", Title: "Logout"},
{Path: "/settings", Title: "Overview", Breadcrumb: "Overview"},
{Path: "/settings/healthchecks", Title: "Healthchecks", Breadcrumb: "Healthchecks"},
{Path: "/settings/healthchecks/create", Title: "Healthchecks Create", Breadcrumb: "Create"},
{Path: "/settings/cronjobs", Title: "Cronjobs", Breadcrumb: "Cronjobs"},
{Path: "/settings/workers", Title: "Workers", Breadcrumb: "Workers"},
{Path: "/temporal", Title: "Temporal", Breadcrumb: "Temporal"},
{Path: "/oauth2/logout", Title: "Logout", Breadcrumb: "Logout"},
}
var SettingsNavbar = []*components.Page{
GetPageByTitle(SettingsPages, "Overview"),
GetPageByTitle(SettingsPages, "Healthchecks"),
GetPageByTitle(SettingsPages, "Cronjobs"),
GetPageByTitle(SettingsPages, "Workers"),
GetPageByTitle(SettingsPages, "Temporal"),
GetPageByTitle(SettingsPages, "Logout"),
}
func (h *BaseHandler) SettingsOverviewGET(w http.ResponseWriter, r *http.Request, user *AuthenticatedUser) {
@ -35,40 +59,11 @@ func (h *BaseHandler) SettingsOverviewGET(w http.ResponseWriter, r *http.Request
return
}
err = ts.ExecuteTemplate(w, "base", &Settings{
Base: &components.Base{
Page: GetPageByTitle(Pages, "Settings"),
Pages: Pages,
},
SettingsPage: GetPageByTitle(SettingsPages, "Overview"),
SettingsPages: SettingsPages,
User: user,
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
func (h *BaseHandler) SettingsHealthchecksGET(w http.ResponseWriter, r *http.Request, user *AuthenticatedUser) {
ts, err := template.ParseFS(templates.Templates,
"components/base.tmpl",
"components/settings.tmpl",
"pages/settings_healthchecks.tmpl",
)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = ts.ExecuteTemplate(w, "base", &Settings{
Base: &components.Base{
Page: GetPageByTitle(Pages, "Settings"),
Pages: Pages,
},
SettingsPage: GetPageByTitle(SettingsPages, "Healthchecks"),
SettingsPages: SettingsPages,
User: user,
})
err = ts.ExecuteTemplate(w, "base", NewSettings(
user,
GetPageByTitle(SettingsPages, "Overview"),
[]*components.Page{GetPageByTitle(SettingsPages, "Overview")},
))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}

View file

@ -0,0 +1,136 @@
package handlers
import (
"context"
"fmt"
"net/http"
"strconv"
"text/template"
"code.tjo.space/mentos1386/zdravko/internal/models"
"code.tjo.space/mentos1386/zdravko/web/templates"
"code.tjo.space/mentos1386/zdravko/web/templates/components"
"github.com/gorilla/mux"
)
type SettingsHealthchecks struct {
*Settings
Healthchecks []*models.HealthcheckHTTP
HealthchecksLength int
}
type SettingsHealthcheck struct {
*Settings
Healthcheck *models.HealthcheckHTTP
}
func (h *BaseHandler) SettingsHealthchecksGET(w http.ResponseWriter, r *http.Request, user *AuthenticatedUser) {
ts, err := template.ParseFS(templates.Templates,
"components/base.tmpl",
"components/settings.tmpl",
"pages/settings_healthchecks.tmpl",
)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
healthchecks, err := h.query.HealthcheckHTTP.WithContext(context.Background()).Find()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
err = ts.ExecuteTemplate(w, "base", &SettingsHealthchecks{
Settings: NewSettings(
user,
GetPageByTitle(SettingsPages, "Healthchecks"),
[]*components.Page{GetPageByTitle(SettingsPages, "Healthchecks")},
),
Healthchecks: healthchecks,
HealthchecksLength: len(healthchecks),
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
func (h *BaseHandler) SettingsHealthchecksDescribeGET(w http.ResponseWriter, r *http.Request, user *AuthenticatedUser) {
vars := mux.Vars(r)
id, err := strconv.ParseUint(vars["id"], 10, 32)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
ts, err := template.ParseFS(templates.Templates,
"components/base.tmpl",
"components/settings.tmpl",
"pages/settings_healthchecks_describe.tmpl",
)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
healthcheck, err := h.query.HealthcheckHTTP.WithContext(context.Background()).Where(
h.query.HealthcheckHTTP.ID.Eq(uint(id)),
).First()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
err = ts.ExecuteTemplate(w, "base", &SettingsHealthcheck{
Settings: NewSettings(
user,
GetPageByTitle(SettingsPages, "Healthchecks"),
[]*components.Page{
GetPageByTitle(SettingsPages, "Healthchecks"),
&components.Page{
Path: fmt.Sprintf("/settings/healthchecks/%d", id),
Title: "Describe",
Breadcrumb: healthcheck.Name,
},
}),
Healthcheck: healthcheck,
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
func (h *BaseHandler) SettingsHealthchecksCreateGET(w http.ResponseWriter, r *http.Request, user *AuthenticatedUser) {
ts, err := template.ParseFS(templates.Templates,
"components/base.tmpl",
"components/settings.tmpl",
"pages/settings_healthchecks_create.tmpl",
)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = ts.ExecuteTemplate(w, "base", NewSettings(
user,
GetPageByTitle(SettingsPages, "Healthchecks"),
[]*components.Page{
GetPageByTitle(SettingsPages, "Healthchecks"),
GetPageByTitle(SettingsPages, "Healthchecks Create"),
},
))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
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"),
}
h.db.Create(healthcheck)
http.Redirect(w, r, "/settings/healthchecks", http.StatusTemporaryRedirect)
}

View file

@ -1,6 +1,10 @@
package models
import "time"
import (
"time"
"gorm.io/gorm"
)
type OAuth2State struct {
State string `gorm:"primary_key"`
@ -8,8 +12,30 @@ type OAuth2State struct {
}
type Healthcheck struct {
ID uint `gorm:"primary_key"`
Name string
gorm.Model
Name string `gorm:"unique"`
Status string // UP, DOWN
UptimePercentage float64
Schedule string
}
type HealthcheckHTTP struct {
gorm.Model
Healthcheck
URL string
Method string
}
type HealthcheckTCP struct {
gorm.Model
Healthcheck
Hostname string
Port int
}
type Cronjob struct {
gorm.Model
Name string `gorm:"unique"`
Schedule string
Buffer int
}

View file

@ -0,0 +1,412 @@
// 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 newCronjob(db *gorm.DB, opts ...gen.DOOption) cronjob {
_cronjob := cronjob{}
_cronjob.cronjobDo.UseDB(db, opts...)
_cronjob.cronjobDo.UseModel(&models.Cronjob{})
tableName := _cronjob.cronjobDo.TableName()
_cronjob.ALL = field.NewAsterisk(tableName)
_cronjob.ID = field.NewUint(tableName, "id")
_cronjob.CreatedAt = field.NewTime(tableName, "created_at")
_cronjob.UpdatedAt = field.NewTime(tableName, "updated_at")
_cronjob.DeletedAt = field.NewField(tableName, "deleted_at")
_cronjob.Name = field.NewString(tableName, "name")
_cronjob.Schedule = field.NewString(tableName, "schedule")
_cronjob.Buffer = field.NewInt(tableName, "buffer")
_cronjob.fillFieldMap()
return _cronjob
}
type cronjob struct {
cronjobDo cronjobDo
ALL field.Asterisk
ID field.Uint
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
Name field.String
Schedule field.String
Buffer field.Int
fieldMap map[string]field.Expr
}
func (c cronjob) Table(newTableName string) *cronjob {
c.cronjobDo.UseTable(newTableName)
return c.updateTableName(newTableName)
}
func (c cronjob) As(alias string) *cronjob {
c.cronjobDo.DO = *(c.cronjobDo.As(alias).(*gen.DO))
return c.updateTableName(alias)
}
func (c *cronjob) updateTableName(table string) *cronjob {
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.Name = field.NewString(table, "name")
c.Schedule = field.NewString(table, "schedule")
c.Buffer = field.NewInt(table, "buffer")
c.fillFieldMap()
return c
}
func (c *cronjob) WithContext(ctx context.Context) ICronjobDo { return c.cronjobDo.WithContext(ctx) }
func (c cronjob) TableName() string { return c.cronjobDo.TableName() }
func (c cronjob) Alias() string { return c.cronjobDo.Alias() }
func (c cronjob) Columns(cols ...field.Expr) gen.Columns { return c.cronjobDo.Columns(cols...) }
func (c *cronjob) 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 *cronjob) fillFieldMap() {
c.fieldMap = make(map[string]field.Expr, 7)
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["name"] = c.Name
c.fieldMap["schedule"] = c.Schedule
c.fieldMap["buffer"] = c.Buffer
}
func (c cronjob) clone(db *gorm.DB) cronjob {
c.cronjobDo.ReplaceConnPool(db.Statement.ConnPool)
return c
}
func (c cronjob) replaceDB(db *gorm.DB) cronjob {
c.cronjobDo.ReplaceDB(db)
return c
}
type cronjobDo struct{ gen.DO }
type ICronjobDo interface {
gen.SubQuery
Debug() ICronjobDo
WithContext(ctx context.Context) ICronjobDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() ICronjobDo
WriteDB() ICronjobDo
As(alias string) gen.Dao
Session(config *gorm.Session) ICronjobDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) ICronjobDo
Not(conds ...gen.Condition) ICronjobDo
Or(conds ...gen.Condition) ICronjobDo
Select(conds ...field.Expr) ICronjobDo
Where(conds ...gen.Condition) ICronjobDo
Order(conds ...field.Expr) ICronjobDo
Distinct(cols ...field.Expr) ICronjobDo
Omit(cols ...field.Expr) ICronjobDo
Join(table schema.Tabler, on ...field.Expr) ICronjobDo
LeftJoin(table schema.Tabler, on ...field.Expr) ICronjobDo
RightJoin(table schema.Tabler, on ...field.Expr) ICronjobDo
Group(cols ...field.Expr) ICronjobDo
Having(conds ...gen.Condition) ICronjobDo
Limit(limit int) ICronjobDo
Offset(offset int) ICronjobDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) ICronjobDo
Unscoped() ICronjobDo
Create(values ...*models.Cronjob) error
CreateInBatches(values []*models.Cronjob, batchSize int) error
Save(values ...*models.Cronjob) error
First() (*models.Cronjob, error)
Take() (*models.Cronjob, error)
Last() (*models.Cronjob, error)
Find() ([]*models.Cronjob, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Cronjob, err error)
FindInBatches(result *[]*models.Cronjob, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*models.Cronjob) (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) ICronjobDo
Assign(attrs ...field.AssignExpr) ICronjobDo
Joins(fields ...field.RelationField) ICronjobDo
Preload(fields ...field.RelationField) ICronjobDo
FirstOrInit() (*models.Cronjob, error)
FirstOrCreate() (*models.Cronjob, error)
FindByPage(offset int, limit int) (result []*models.Cronjob, 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) ICronjobDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (c cronjobDo) Debug() ICronjobDo {
return c.withDO(c.DO.Debug())
}
func (c cronjobDo) WithContext(ctx context.Context) ICronjobDo {
return c.withDO(c.DO.WithContext(ctx))
}
func (c cronjobDo) ReadDB() ICronjobDo {
return c.Clauses(dbresolver.Read)
}
func (c cronjobDo) WriteDB() ICronjobDo {
return c.Clauses(dbresolver.Write)
}
func (c cronjobDo) Session(config *gorm.Session) ICronjobDo {
return c.withDO(c.DO.Session(config))
}
func (c cronjobDo) Clauses(conds ...clause.Expression) ICronjobDo {
return c.withDO(c.DO.Clauses(conds...))
}
func (c cronjobDo) Returning(value interface{}, columns ...string) ICronjobDo {
return c.withDO(c.DO.Returning(value, columns...))
}
func (c cronjobDo) Not(conds ...gen.Condition) ICronjobDo {
return c.withDO(c.DO.Not(conds...))
}
func (c cronjobDo) Or(conds ...gen.Condition) ICronjobDo {
return c.withDO(c.DO.Or(conds...))
}
func (c cronjobDo) Select(conds ...field.Expr) ICronjobDo {
return c.withDO(c.DO.Select(conds...))
}
func (c cronjobDo) Where(conds ...gen.Condition) ICronjobDo {
return c.withDO(c.DO.Where(conds...))
}
func (c cronjobDo) Order(conds ...field.Expr) ICronjobDo {
return c.withDO(c.DO.Order(conds...))
}
func (c cronjobDo) Distinct(cols ...field.Expr) ICronjobDo {
return c.withDO(c.DO.Distinct(cols...))
}
func (c cronjobDo) Omit(cols ...field.Expr) ICronjobDo {
return c.withDO(c.DO.Omit(cols...))
}
func (c cronjobDo) Join(table schema.Tabler, on ...field.Expr) ICronjobDo {
return c.withDO(c.DO.Join(table, on...))
}
func (c cronjobDo) LeftJoin(table schema.Tabler, on ...field.Expr) ICronjobDo {
return c.withDO(c.DO.LeftJoin(table, on...))
}
func (c cronjobDo) RightJoin(table schema.Tabler, on ...field.Expr) ICronjobDo {
return c.withDO(c.DO.RightJoin(table, on...))
}
func (c cronjobDo) Group(cols ...field.Expr) ICronjobDo {
return c.withDO(c.DO.Group(cols...))
}
func (c cronjobDo) Having(conds ...gen.Condition) ICronjobDo {
return c.withDO(c.DO.Having(conds...))
}
func (c cronjobDo) Limit(limit int) ICronjobDo {
return c.withDO(c.DO.Limit(limit))
}
func (c cronjobDo) Offset(offset int) ICronjobDo {
return c.withDO(c.DO.Offset(offset))
}
func (c cronjobDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ICronjobDo {
return c.withDO(c.DO.Scopes(funcs...))
}
func (c cronjobDo) Unscoped() ICronjobDo {
return c.withDO(c.DO.Unscoped())
}
func (c cronjobDo) Create(values ...*models.Cronjob) error {
if len(values) == 0 {
return nil
}
return c.DO.Create(values)
}
func (c cronjobDo) CreateInBatches(values []*models.Cronjob, 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 cronjobDo) Save(values ...*models.Cronjob) error {
if len(values) == 0 {
return nil
}
return c.DO.Save(values)
}
func (c cronjobDo) First() (*models.Cronjob, error) {
if result, err := c.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.Cronjob), nil
}
}
func (c cronjobDo) Take() (*models.Cronjob, error) {
if result, err := c.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.Cronjob), nil
}
}
func (c cronjobDo) Last() (*models.Cronjob, error) {
if result, err := c.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.Cronjob), nil
}
}
func (c cronjobDo) Find() ([]*models.Cronjob, error) {
result, err := c.DO.Find()
return result.([]*models.Cronjob), err
}
func (c cronjobDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Cronjob, err error) {
buf := make([]*models.Cronjob, 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 cronjobDo) FindInBatches(result *[]*models.Cronjob, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return c.DO.FindInBatches(result, batchSize, fc)
}
func (c cronjobDo) Attrs(attrs ...field.AssignExpr) ICronjobDo {
return c.withDO(c.DO.Attrs(attrs...))
}
func (c cronjobDo) Assign(attrs ...field.AssignExpr) ICronjobDo {
return c.withDO(c.DO.Assign(attrs...))
}
func (c cronjobDo) Joins(fields ...field.RelationField) ICronjobDo {
for _, _f := range fields {
c = *c.withDO(c.DO.Joins(_f))
}
return &c
}
func (c cronjobDo) Preload(fields ...field.RelationField) ICronjobDo {
for _, _f := range fields {
c = *c.withDO(c.DO.Preload(_f))
}
return &c
}
func (c cronjobDo) FirstOrInit() (*models.Cronjob, error) {
if result, err := c.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.Cronjob), nil
}
}
func (c cronjobDo) FirstOrCreate() (*models.Cronjob, error) {
if result, err := c.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.Cronjob), nil
}
}
func (c cronjobDo) FindByPage(offset int, limit int) (result []*models.Cronjob, 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 cronjobDo) 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 cronjobDo) Scan(result interface{}) (err error) {
return c.DO.Scan(result)
}
func (c cronjobDo) Delete(models ...*models.Cronjob) (result gen.ResultInfo, err error) {
return c.DO.Delete(models)
}
func (c *cronjobDo) withDO(do gen.Dao) *cronjobDo {
c.DO = *do.(*gen.DO)
return c
}

View file

@ -16,39 +16,49 @@ import (
)
var (
Q = new(Query)
Healthcheck *healthcheck
OAuth2State *oAuth2State
Q = new(Query)
Cronjob *cronjob
HealthcheckHTTP *healthcheckHTTP
HealthcheckTCP *healthcheckTCP
OAuth2State *oAuth2State
)
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
Healthcheck = &Q.Healthcheck
Cronjob = &Q.Cronjob
HealthcheckHTTP = &Q.HealthcheckHTTP
HealthcheckTCP = &Q.HealthcheckTCP
OAuth2State = &Q.OAuth2State
}
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
Healthcheck: newHealthcheck(db, opts...),
OAuth2State: newOAuth2State(db, opts...),
db: db,
Cronjob: newCronjob(db, opts...),
HealthcheckHTTP: newHealthcheckHTTP(db, opts...),
HealthcheckTCP: newHealthcheckTCP(db, opts...),
OAuth2State: newOAuth2State(db, opts...),
}
}
type Query struct {
db *gorm.DB
Healthcheck healthcheck
OAuth2State oAuth2State
Cronjob cronjob
HealthcheckHTTP healthcheckHTTP
HealthcheckTCP healthcheckTCP
OAuth2State oAuth2State
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
Healthcheck: q.Healthcheck.clone(db),
OAuth2State: q.OAuth2State.clone(db),
db: db,
Cronjob: q.Cronjob.clone(db),
HealthcheckHTTP: q.HealthcheckHTTP.clone(db),
HealthcheckTCP: q.HealthcheckTCP.clone(db),
OAuth2State: q.OAuth2State.clone(db),
}
}
@ -62,21 +72,27 @@ func (q *Query) WriteDB() *Query {
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
Healthcheck: q.Healthcheck.replaceDB(db),
OAuth2State: q.OAuth2State.replaceDB(db),
db: db,
Cronjob: q.Cronjob.replaceDB(db),
HealthcheckHTTP: q.HealthcheckHTTP.replaceDB(db),
HealthcheckTCP: q.HealthcheckTCP.replaceDB(db),
OAuth2State: q.OAuth2State.replaceDB(db),
}
}
type queryCtx struct {
Healthcheck IHealthcheckDo
OAuth2State IOAuth2StateDo
Cronjob ICronjobDo
HealthcheckHTTP IHealthcheckHTTPDo
HealthcheckTCP IHealthcheckTCPDo
OAuth2State IOAuth2StateDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
Healthcheck: q.Healthcheck.WithContext(ctx),
OAuth2State: q.OAuth2State.WithContext(ctx),
Cronjob: q.Cronjob.WithContext(ctx),
HealthcheckHTTP: q.HealthcheckHTTP.WithContext(ctx),
HealthcheckTCP: q.HealthcheckTCP.WithContext(ctx),
OAuth2State: q.OAuth2State.WithContext(ctx),
}
}

View file

@ -0,0 +1,428 @@
// 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 newHealthcheckHTTP(db *gorm.DB, opts ...gen.DOOption) healthcheckHTTP {
_healthcheckHTTP := 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")
_healthcheckHTTP.fillFieldMap()
return _healthcheckHTTP
}
type healthcheckHTTP struct {
healthcheckHTTPDo healthcheckHTTPDo
ALL field.Asterisk
ID field.Uint
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
Name field.String
Status field.String
UptimePercentage field.Float64
Schedule field.String
URL field.String
Method field.String
fieldMap map[string]field.Expr
}
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))
return h.updateTableName(alias)
}
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")
h.UpdatedAt = field.NewTime(table, "updated_at")
h.DeletedAt = field.NewField(table, "deleted_at")
h.Name = field.NewString(table, "name")
h.Status = field.NewString(table, "status")
h.UptimePercentage = field.NewFloat64(table, "uptime_percentage")
h.Schedule = field.NewString(table, "schedule")
h.URL = field.NewString(table, "url")
h.Method = field.NewString(table, "method")
h.fillFieldMap()
return h
}
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) Alias() string { return h.healthcheckHTTPDo.Alias() }
func (h healthcheckHTTP) Columns(cols ...field.Expr) gen.Columns {
return h.healthcheckHTTPDo.Columns(cols...)
}
func (h *healthcheckHTTP) 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 *healthcheckHTTP) fillFieldMap() {
h.fieldMap = make(map[string]field.Expr, 10)
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["name"] = h.Name
h.fieldMap["status"] = h.Status
h.fieldMap["uptime_percentage"] = h.UptimePercentage
h.fieldMap["schedule"] = h.Schedule
h.fieldMap["url"] = h.URL
h.fieldMap["method"] = h.Method
}
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)
return h
}
type healthcheckHTTPDo struct{ gen.DO }
type IHealthcheckHTTPDo interface {
gen.SubQuery
Debug() IHealthcheckHTTPDo
WithContext(ctx context.Context) IHealthcheckHTTPDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IHealthcheckHTTPDo
WriteDB() IHealthcheckHTTPDo
As(alias string) gen.Dao
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
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
Pluck(column field.Expr, dest interface{}) 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)
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) 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
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (h healthcheckHTTPDo) Debug() IHealthcheckHTTPDo {
return h.withDO(h.DO.Debug())
}
func (h healthcheckHTTPDo) WithContext(ctx context.Context) IHealthcheckHTTPDo {
return h.withDO(h.DO.WithContext(ctx))
}
func (h healthcheckHTTPDo) ReadDB() IHealthcheckHTTPDo {
return h.Clauses(dbresolver.Read)
}
func (h healthcheckHTTPDo) WriteDB() IHealthcheckHTTPDo {
return h.Clauses(dbresolver.Write)
}
func (h healthcheckHTTPDo) Session(config *gorm.Session) IHealthcheckHTTPDo {
return h.withDO(h.DO.Session(config))
}
func (h healthcheckHTTPDo) Clauses(conds ...clause.Expression) IHealthcheckHTTPDo {
return h.withDO(h.DO.Clauses(conds...))
}
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 {
return h.withDO(h.DO.Not(conds...))
}
func (h healthcheckHTTPDo) Or(conds ...gen.Condition) IHealthcheckHTTPDo {
return h.withDO(h.DO.Or(conds...))
}
func (h healthcheckHTTPDo) Select(conds ...field.Expr) IHealthcheckHTTPDo {
return h.withDO(h.DO.Select(conds...))
}
func (h healthcheckHTTPDo) Where(conds ...gen.Condition) IHealthcheckHTTPDo {
return h.withDO(h.DO.Where(conds...))
}
func (h healthcheckHTTPDo) Order(conds ...field.Expr) IHealthcheckHTTPDo {
return h.withDO(h.DO.Order(conds...))
}
func (h healthcheckHTTPDo) Distinct(cols ...field.Expr) IHealthcheckHTTPDo {
return h.withDO(h.DO.Distinct(cols...))
}
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 {
return h.withDO(h.DO.Join(table, on...))
}
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 {
return h.withDO(h.DO.RightJoin(table, on...))
}
func (h healthcheckHTTPDo) Group(cols ...field.Expr) IHealthcheckHTTPDo {
return h.withDO(h.DO.Group(cols...))
}
func (h healthcheckHTTPDo) Having(conds ...gen.Condition) IHealthcheckHTTPDo {
return h.withDO(h.DO.Having(conds...))
}
func (h healthcheckHTTPDo) Limit(limit int) IHealthcheckHTTPDo {
return h.withDO(h.DO.Limit(limit))
}
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 {
return h.withDO(h.DO.Scopes(funcs...))
}
func (h healthcheckHTTPDo) Unscoped() IHealthcheckHTTPDo {
return h.withDO(h.DO.Unscoped())
}
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 {
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 {
if len(values) == 0 {
return nil
}
return h.DO.Save(values)
}
func (h healthcheckHTTPDo) First() (*models.HealthcheckHTTP, error) {
if result, err := h.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckHTTP), nil
}
}
func (h healthcheckHTTPDo) Take() (*models.HealthcheckHTTP, error) {
if result, err := h.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckHTTP), nil
}
}
func (h healthcheckHTTPDo) Last() (*models.HealthcheckHTTP, error) {
if result, err := h.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckHTTP), nil
}
}
func (h healthcheckHTTPDo) Find() ([]*models.HealthcheckHTTP, error) {
result, err := h.DO.Find()
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)
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 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 {
return h.withDO(h.DO.Attrs(attrs...))
}
func (h healthcheckHTTPDo) Assign(attrs ...field.AssignExpr) IHealthcheckHTTPDo {
return h.withDO(h.DO.Assign(attrs...))
}
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 {
for _, _f := range fields {
h = *h.withDO(h.DO.Preload(_f))
}
return &h
}
func (h healthcheckHTTPDo) FirstOrInit() (*models.HealthcheckHTTP, error) {
if result, err := h.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckHTTP), nil
}
}
func (h healthcheckHTTPDo) FirstOrCreate() (*models.HealthcheckHTTP, error) {
if result, err := h.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckHTTP), nil
}
}
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
}
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 healthcheckHTTPDo) 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 healthcheckHTTPDo) Scan(result interface{}) (err error) {
return h.DO.Scan(result)
}
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 {
h.DO = *do.(*gen.DO)
return h
}

View file

@ -0,0 +1,428 @@
// 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 newHealthcheckTCP(db *gorm.DB, opts ...gen.DOOption) healthcheckTCP {
_healthcheckTCP := 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")
_healthcheckTCP.fillFieldMap()
return _healthcheckTCP
}
type healthcheckTCP struct {
healthcheckTCPDo healthcheckTCPDo
ALL field.Asterisk
ID field.Uint
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
Name field.String
Status field.String
UptimePercentage field.Float64
Schedule field.String
Hostname field.String
Port field.Int
fieldMap map[string]field.Expr
}
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))
return h.updateTableName(alias)
}
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")
h.UpdatedAt = field.NewTime(table, "updated_at")
h.DeletedAt = field.NewField(table, "deleted_at")
h.Name = field.NewString(table, "name")
h.Status = field.NewString(table, "status")
h.UptimePercentage = field.NewFloat64(table, "uptime_percentage")
h.Schedule = field.NewString(table, "schedule")
h.Hostname = field.NewString(table, "hostname")
h.Port = field.NewInt(table, "port")
h.fillFieldMap()
return h
}
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) Alias() string { return h.healthcheckTCPDo.Alias() }
func (h healthcheckTCP) Columns(cols ...field.Expr) gen.Columns {
return h.healthcheckTCPDo.Columns(cols...)
}
func (h *healthcheckTCP) 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 *healthcheckTCP) fillFieldMap() {
h.fieldMap = make(map[string]field.Expr, 10)
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["name"] = h.Name
h.fieldMap["status"] = h.Status
h.fieldMap["uptime_percentage"] = h.UptimePercentage
h.fieldMap["schedule"] = h.Schedule
h.fieldMap["hostname"] = h.Hostname
h.fieldMap["port"] = h.Port
}
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)
return h
}
type healthcheckTCPDo struct{ gen.DO }
type IHealthcheckTCPDo interface {
gen.SubQuery
Debug() IHealthcheckTCPDo
WithContext(ctx context.Context) IHealthcheckTCPDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IHealthcheckTCPDo
WriteDB() IHealthcheckTCPDo
As(alias string) gen.Dao
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
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
Pluck(column field.Expr, dest interface{}) 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)
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) 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
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (h healthcheckTCPDo) Debug() IHealthcheckTCPDo {
return h.withDO(h.DO.Debug())
}
func (h healthcheckTCPDo) WithContext(ctx context.Context) IHealthcheckTCPDo {
return h.withDO(h.DO.WithContext(ctx))
}
func (h healthcheckTCPDo) ReadDB() IHealthcheckTCPDo {
return h.Clauses(dbresolver.Read)
}
func (h healthcheckTCPDo) WriteDB() IHealthcheckTCPDo {
return h.Clauses(dbresolver.Write)
}
func (h healthcheckTCPDo) Session(config *gorm.Session) IHealthcheckTCPDo {
return h.withDO(h.DO.Session(config))
}
func (h healthcheckTCPDo) Clauses(conds ...clause.Expression) IHealthcheckTCPDo {
return h.withDO(h.DO.Clauses(conds...))
}
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 {
return h.withDO(h.DO.Not(conds...))
}
func (h healthcheckTCPDo) Or(conds ...gen.Condition) IHealthcheckTCPDo {
return h.withDO(h.DO.Or(conds...))
}
func (h healthcheckTCPDo) Select(conds ...field.Expr) IHealthcheckTCPDo {
return h.withDO(h.DO.Select(conds...))
}
func (h healthcheckTCPDo) Where(conds ...gen.Condition) IHealthcheckTCPDo {
return h.withDO(h.DO.Where(conds...))
}
func (h healthcheckTCPDo) Order(conds ...field.Expr) IHealthcheckTCPDo {
return h.withDO(h.DO.Order(conds...))
}
func (h healthcheckTCPDo) Distinct(cols ...field.Expr) IHealthcheckTCPDo {
return h.withDO(h.DO.Distinct(cols...))
}
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 {
return h.withDO(h.DO.Join(table, on...))
}
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 {
return h.withDO(h.DO.RightJoin(table, on...))
}
func (h healthcheckTCPDo) Group(cols ...field.Expr) IHealthcheckTCPDo {
return h.withDO(h.DO.Group(cols...))
}
func (h healthcheckTCPDo) Having(conds ...gen.Condition) IHealthcheckTCPDo {
return h.withDO(h.DO.Having(conds...))
}
func (h healthcheckTCPDo) Limit(limit int) IHealthcheckTCPDo {
return h.withDO(h.DO.Limit(limit))
}
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 {
return h.withDO(h.DO.Scopes(funcs...))
}
func (h healthcheckTCPDo) Unscoped() IHealthcheckTCPDo {
return h.withDO(h.DO.Unscoped())
}
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 {
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 {
if len(values) == 0 {
return nil
}
return h.DO.Save(values)
}
func (h healthcheckTCPDo) First() (*models.HealthcheckTCP, error) {
if result, err := h.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckTCP), nil
}
}
func (h healthcheckTCPDo) Take() (*models.HealthcheckTCP, error) {
if result, err := h.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckTCP), nil
}
}
func (h healthcheckTCPDo) Last() (*models.HealthcheckTCP, error) {
if result, err := h.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckTCP), nil
}
}
func (h healthcheckTCPDo) Find() ([]*models.HealthcheckTCP, error) {
result, err := h.DO.Find()
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)
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 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 {
return h.withDO(h.DO.Attrs(attrs...))
}
func (h healthcheckTCPDo) Assign(attrs ...field.AssignExpr) IHealthcheckTCPDo {
return h.withDO(h.DO.Assign(attrs...))
}
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 {
for _, _f := range fields {
h = *h.withDO(h.DO.Preload(_f))
}
return &h
}
func (h healthcheckTCPDo) FirstOrInit() (*models.HealthcheckTCP, error) {
if result, err := h.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckTCP), nil
}
}
func (h healthcheckTCPDo) FirstOrCreate() (*models.HealthcheckTCP, error) {
if result, err := h.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.HealthcheckTCP), nil
}
}
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
}
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 healthcheckTCPDo) 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 healthcheckTCPDo) Scan(result interface{}) (err error) {
return h.DO.Scan(result)
}
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 {
h.DO = *do.(*gen.DO)
return h
}

View file

@ -1,402 +0,0 @@
// 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 newHealthcheck(db *gorm.DB, opts ...gen.DOOption) healthcheck {
_healthcheck := healthcheck{}
_healthcheck.healthcheckDo.UseDB(db, opts...)
_healthcheck.healthcheckDo.UseModel(&models.Healthcheck{})
tableName := _healthcheck.healthcheckDo.TableName()
_healthcheck.ALL = field.NewAsterisk(tableName)
_healthcheck.ID = field.NewUint(tableName, "id")
_healthcheck.Name = field.NewString(tableName, "name")
_healthcheck.Status = field.NewString(tableName, "status")
_healthcheck.UptimePercentage = field.NewFloat64(tableName, "uptime_percentage")
_healthcheck.fillFieldMap()
return _healthcheck
}
type healthcheck struct {
healthcheckDo healthcheckDo
ALL field.Asterisk
ID field.Uint
Name field.String
Status field.String
UptimePercentage field.Float64
fieldMap map[string]field.Expr
}
func (h healthcheck) Table(newTableName string) *healthcheck {
h.healthcheckDo.UseTable(newTableName)
return h.updateTableName(newTableName)
}
func (h healthcheck) As(alias string) *healthcheck {
h.healthcheckDo.DO = *(h.healthcheckDo.As(alias).(*gen.DO))
return h.updateTableName(alias)
}
func (h *healthcheck) updateTableName(table string) *healthcheck {
h.ALL = field.NewAsterisk(table)
h.ID = field.NewUint(table, "id")
h.Name = field.NewString(table, "name")
h.Status = field.NewString(table, "status")
h.UptimePercentage = field.NewFloat64(table, "uptime_percentage")
h.fillFieldMap()
return h
}
func (h *healthcheck) WithContext(ctx context.Context) IHealthcheckDo {
return h.healthcheckDo.WithContext(ctx)
}
func (h healthcheck) TableName() string { return h.healthcheckDo.TableName() }
func (h healthcheck) Alias() string { return h.healthcheckDo.Alias() }
func (h healthcheck) Columns(cols ...field.Expr) gen.Columns { return h.healthcheckDo.Columns(cols...) }
func (h *healthcheck) 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 *healthcheck) fillFieldMap() {
h.fieldMap = make(map[string]field.Expr, 4)
h.fieldMap["id"] = h.ID
h.fieldMap["name"] = h.Name
h.fieldMap["status"] = h.Status
h.fieldMap["uptime_percentage"] = h.UptimePercentage
}
func (h healthcheck) clone(db *gorm.DB) healthcheck {
h.healthcheckDo.ReplaceConnPool(db.Statement.ConnPool)
return h
}
func (h healthcheck) replaceDB(db *gorm.DB) healthcheck {
h.healthcheckDo.ReplaceDB(db)
return h
}
type healthcheckDo struct{ gen.DO }
type IHealthcheckDo interface {
gen.SubQuery
Debug() IHealthcheckDo
WithContext(ctx context.Context) IHealthcheckDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IHealthcheckDo
WriteDB() IHealthcheckDo
As(alias string) gen.Dao
Session(config *gorm.Session) IHealthcheckDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IHealthcheckDo
Not(conds ...gen.Condition) IHealthcheckDo
Or(conds ...gen.Condition) IHealthcheckDo
Select(conds ...field.Expr) IHealthcheckDo
Where(conds ...gen.Condition) IHealthcheckDo
Order(conds ...field.Expr) IHealthcheckDo
Distinct(cols ...field.Expr) IHealthcheckDo
Omit(cols ...field.Expr) IHealthcheckDo
Join(table schema.Tabler, on ...field.Expr) IHealthcheckDo
LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckDo
RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckDo
Group(cols ...field.Expr) IHealthcheckDo
Having(conds ...gen.Condition) IHealthcheckDo
Limit(limit int) IHealthcheckDo
Offset(offset int) IHealthcheckDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckDo
Unscoped() IHealthcheckDo
Create(values ...*models.Healthcheck) error
CreateInBatches(values []*models.Healthcheck, batchSize int) error
Save(values ...*models.Healthcheck) error
First() (*models.Healthcheck, error)
Take() (*models.Healthcheck, error)
Last() (*models.Healthcheck, error)
Find() ([]*models.Healthcheck, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Healthcheck, err error)
FindInBatches(result *[]*models.Healthcheck, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*models.Healthcheck) (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) IHealthcheckDo
Assign(attrs ...field.AssignExpr) IHealthcheckDo
Joins(fields ...field.RelationField) IHealthcheckDo
Preload(fields ...field.RelationField) IHealthcheckDo
FirstOrInit() (*models.Healthcheck, error)
FirstOrCreate() (*models.Healthcheck, error)
FindByPage(offset int, limit int) (result []*models.Healthcheck, 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) IHealthcheckDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (h healthcheckDo) Debug() IHealthcheckDo {
return h.withDO(h.DO.Debug())
}
func (h healthcheckDo) WithContext(ctx context.Context) IHealthcheckDo {
return h.withDO(h.DO.WithContext(ctx))
}
func (h healthcheckDo) ReadDB() IHealthcheckDo {
return h.Clauses(dbresolver.Read)
}
func (h healthcheckDo) WriteDB() IHealthcheckDo {
return h.Clauses(dbresolver.Write)
}
func (h healthcheckDo) Session(config *gorm.Session) IHealthcheckDo {
return h.withDO(h.DO.Session(config))
}
func (h healthcheckDo) Clauses(conds ...clause.Expression) IHealthcheckDo {
return h.withDO(h.DO.Clauses(conds...))
}
func (h healthcheckDo) Returning(value interface{}, columns ...string) IHealthcheckDo {
return h.withDO(h.DO.Returning(value, columns...))
}
func (h healthcheckDo) Not(conds ...gen.Condition) IHealthcheckDo {
return h.withDO(h.DO.Not(conds...))
}
func (h healthcheckDo) Or(conds ...gen.Condition) IHealthcheckDo {
return h.withDO(h.DO.Or(conds...))
}
func (h healthcheckDo) Select(conds ...field.Expr) IHealthcheckDo {
return h.withDO(h.DO.Select(conds...))
}
func (h healthcheckDo) Where(conds ...gen.Condition) IHealthcheckDo {
return h.withDO(h.DO.Where(conds...))
}
func (h healthcheckDo) Order(conds ...field.Expr) IHealthcheckDo {
return h.withDO(h.DO.Order(conds...))
}
func (h healthcheckDo) Distinct(cols ...field.Expr) IHealthcheckDo {
return h.withDO(h.DO.Distinct(cols...))
}
func (h healthcheckDo) Omit(cols ...field.Expr) IHealthcheckDo {
return h.withDO(h.DO.Omit(cols...))
}
func (h healthcheckDo) Join(table schema.Tabler, on ...field.Expr) IHealthcheckDo {
return h.withDO(h.DO.Join(table, on...))
}
func (h healthcheckDo) LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckDo {
return h.withDO(h.DO.LeftJoin(table, on...))
}
func (h healthcheckDo) RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckDo {
return h.withDO(h.DO.RightJoin(table, on...))
}
func (h healthcheckDo) Group(cols ...field.Expr) IHealthcheckDo {
return h.withDO(h.DO.Group(cols...))
}
func (h healthcheckDo) Having(conds ...gen.Condition) IHealthcheckDo {
return h.withDO(h.DO.Having(conds...))
}
func (h healthcheckDo) Limit(limit int) IHealthcheckDo {
return h.withDO(h.DO.Limit(limit))
}
func (h healthcheckDo) Offset(offset int) IHealthcheckDo {
return h.withDO(h.DO.Offset(offset))
}
func (h healthcheckDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckDo {
return h.withDO(h.DO.Scopes(funcs...))
}
func (h healthcheckDo) Unscoped() IHealthcheckDo {
return h.withDO(h.DO.Unscoped())
}
func (h healthcheckDo) Create(values ...*models.Healthcheck) error {
if len(values) == 0 {
return nil
}
return h.DO.Create(values)
}
func (h healthcheckDo) CreateInBatches(values []*models.Healthcheck, 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 healthcheckDo) Save(values ...*models.Healthcheck) error {
if len(values) == 0 {
return nil
}
return h.DO.Save(values)
}
func (h healthcheckDo) First() (*models.Healthcheck, error) {
if result, err := h.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.Healthcheck), nil
}
}
func (h healthcheckDo) Take() (*models.Healthcheck, error) {
if result, err := h.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.Healthcheck), nil
}
}
func (h healthcheckDo) Last() (*models.Healthcheck, error) {
if result, err := h.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.Healthcheck), nil
}
}
func (h healthcheckDo) Find() ([]*models.Healthcheck, error) {
result, err := h.DO.Find()
return result.([]*models.Healthcheck), err
}
func (h healthcheckDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Healthcheck, err error) {
buf := make([]*models.Healthcheck, 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 healthcheckDo) FindInBatches(result *[]*models.Healthcheck, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return h.DO.FindInBatches(result, batchSize, fc)
}
func (h healthcheckDo) Attrs(attrs ...field.AssignExpr) IHealthcheckDo {
return h.withDO(h.DO.Attrs(attrs...))
}
func (h healthcheckDo) Assign(attrs ...field.AssignExpr) IHealthcheckDo {
return h.withDO(h.DO.Assign(attrs...))
}
func (h healthcheckDo) Joins(fields ...field.RelationField) IHealthcheckDo {
for _, _f := range fields {
h = *h.withDO(h.DO.Joins(_f))
}
return &h
}
func (h healthcheckDo) Preload(fields ...field.RelationField) IHealthcheckDo {
for _, _f := range fields {
h = *h.withDO(h.DO.Preload(_f))
}
return &h
}
func (h healthcheckDo) FirstOrInit() (*models.Healthcheck, error) {
if result, err := h.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.Healthcheck), nil
}
}
func (h healthcheckDo) FirstOrCreate() (*models.Healthcheck, error) {
if result, err := h.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.Healthcheck), nil
}
}
func (h healthcheckDo) FindByPage(offset int, limit int) (result []*models.Healthcheck, 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 healthcheckDo) 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 healthcheckDo) Scan(result interface{}) (err error) {
return h.DO.Scan(result)
}
func (h healthcheckDo) Delete(models ...*models.Healthcheck) (result gen.ResultInfo, err error) {
return h.DO.Delete(models)
}
func (h *healthcheckDo) withDO(do gen.Dao) *healthcheckDo {
h.DO = *do.(*gen.DO)
return h
}

View file

@ -34,6 +34,7 @@ shell:
# Generate and download all external dependencies.
generate:
rm -rf internal/models/query/*
go generate ./...
_tailwindcss-build:

View file

@ -4,7 +4,7 @@ import (
"fmt"
"time"
"code.tjo.space/mentos1386/zdravko/internal"
internal "code.tjo.space/mentos1386/zdravko/internal/config"
"go.temporal.io/server/common/cluster"
"go.temporal.io/server/common/config"
"go.temporal.io/server/common/persistence/sql/sqlplugin/sqlite"

View file

@ -1,7 +1,7 @@
package temporal
import (
"code.tjo.space/mentos1386/zdravko/internal"
internal "code.tjo.space/mentos1386/zdravko/internal/config"
"github.com/temporalio/ui-server/v2/server"
"github.com/temporalio/ui-server/v2/server/config"
"github.com/temporalio/ui-server/v2/server/server_options"

View file

@ -1,13 +1,15 @@
package main
import (
"code.tjo.space/mentos1386/zdravko/internal"
"code.tjo.space/mentos1386/zdravko/internal/config"
"code.tjo.space/mentos1386/zdravko/internal/models"
"gorm.io/driver/sqlite"
"gorm.io/gen"
"gorm.io/gorm"
)
func main() {
config := internal.NewConfig()
config := config.NewConfig()
// Initialize the generator with configuration
g := gen.NewGenerator(gen.Config{
@ -16,14 +18,17 @@ func main() {
FieldNullable: true,
})
db, _, _ := internal.ConnectToDatabase(config.DatabasePath)
db, err := gorm.Open(sqlite.Open(config.DatabasePath), &gorm.Config{})
if err != nil {
panic(err)
}
// Use the above `*gorm.DB` instance to initialize the generator,
// which is required to generate structs from db when using `GenerateModel/GenerateModelAs`
g.UseDB(db)
// Generate default DAO interface for those specified structs
g.ApplyBasic(models.Healthcheck{}, models.OAuth2State{})
g.ApplyBasic(models.HealthcheckHTTP{}, models.HealthcheckTCP{}, models.Cronjob{}, models.OAuth2State{})
// Execute the generator
g.Execute()

View file

@ -13,7 +13,7 @@
@tailwind utilities;
.navbar {
@apply justify-center flex space-x-2 mt-10;
@apply justify-center flex flex-wrap space-x-2 gap-2 mt-10;
}
.navbar a {
@apply font-bold py-2 px-4 rounded-lg;
@ -32,7 +32,7 @@
}
.sidebar {
@apply w-48 grid gap-2 h-fit text-sm font-medium text-gray-900;
@apply flex flex-row flex-wrap justify-center lg:flex-col lg:w-48 gap-2 h-fit text-sm font-medium text-gray-900;
}
.sidebar a {
@apply w-full block rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-700 focus:text-blue-700;
@ -47,10 +47,13 @@
@apply bg-blue-700 text-white;
}
.breadcrumb {
@apply flex mb-4;
}
.healthchecks {
@apply grid justify-items-stretch justify-stretch items-center mt-20 bg-white shadow-md p-5 rounded-lg;
}
.healthchecks > div:not(:last-child) {
@apply mb-3;
}

View file

@ -598,15 +598,28 @@ video {
grid-column: span 2 / span 2;
}
.mx-1 {
margin-left: 0.25rem;
margin-right: 0.25rem;
}
.mx-auto {
margin-left: auto;
margin-right: auto;
}
.mb-2 {
margin-bottom: 0.5rem;
}
.mb-4 {
margin-bottom: 1rem;
}
.mb-5 {
margin-bottom: 1.25rem;
}
.mb-8 {
margin-bottom: 2rem;
}
@ -615,8 +628,8 @@ video {
margin-inline-end: 0.5rem;
}
.ms-2 {
margin-inline-start: 0.5rem;
.ml-1 {
margin-left: 0.25rem;
}
.mt-1 {
@ -631,6 +644,10 @@ video {
margin-top: 2rem;
}
.block {
display: block;
}
.flex {
display: flex;
}
@ -655,8 +672,12 @@ video {
height: 0.75rem;
}
.h-3\.5 {
height: 0.875rem;
.h-4 {
height: 1rem;
}
.h-5 {
height: 1.25rem;
}
.h-8 {
@ -671,8 +692,12 @@ video {
width: 0.75rem;
}
.w-3\.5 {
width: 0.875rem;
.w-4 {
width: 1rem;
}
.w-5 {
width: 1.25rem;
}
.w-full {
@ -687,6 +712,10 @@ video {
max-width: 1280px;
}
.max-w-sm {
max-width: 24rem;
}
.flex-auto {
flex: 1 1 auto;
}
@ -695,12 +724,12 @@ video {
grid-auto-flow: column;
}
.grid-cols-2 {
grid-template-columns: repeat(2, minmax(0, 1fr));
.grid-cols-1 {
grid-template-columns: repeat(1, minmax(0, 1fr));
}
.grid-cols-\[1fr_100\%\] {
grid-template-columns: 1fr 100%;
.grid-cols-2 {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.flex-col {
@ -727,6 +756,12 @@ 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)));
@ -769,8 +804,13 @@ video {
border-radius: 0.5rem;
}
.border-b {
border-bottom-width: 1px;
.border {
border-width: 1px;
}
.border-gray-300 {
--tw-border-opacity: 1;
border-color: rgb(209 213 219 / var(--tw-border-opacity));
}
.bg-blue-700 {
@ -813,6 +853,14 @@ video {
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
}
.p-2 {
padding: 0.5rem;
}
.p-2\.5 {
padding: 0.625rem;
}
.p-4 {
padding: 1rem;
}
@ -821,6 +869,11 @@ video {
padding: 1.25rem;
}
.px-2 {
padding-left: 0.5rem;
padding-right: 0.5rem;
}
.px-4 {
padding-left: 1rem;
padding-right: 1rem;
@ -836,6 +889,21 @@ video {
padding-right: 1.5rem;
}
.py-1 {
padding-top: 0.25rem;
padding-bottom: 0.25rem;
}
.py-2 {
padding-top: 0.5rem;
padding-bottom: 0.5rem;
}
.py-2\.5 {
padding-top: 0.625rem;
padding-bottom: 0.625rem;
}
.py-3 {
padding-top: 0.75rem;
padding-bottom: 0.75rem;
@ -884,6 +952,11 @@ video {
line-height: 1.25rem;
}
.text-xl {
font-size: 1.25rem;
line-height: 1.75rem;
}
.text-xs {
font-size: 0.75rem;
line-height: 1rem;
@ -926,6 +999,11 @@ video {
color: rgb(37 99 235 / var(--tw-text-opacity));
}
.text-gray-400 {
--tw-text-opacity: 1;
color: rgb(156 163 175 / var(--tw-text-opacity));
}
.text-gray-500 {
--tw-text-opacity: 1;
color: rgb(107 114 128 / var(--tw-text-opacity));
@ -969,7 +1047,9 @@ video {
.navbar {
margin-top: 2.5rem;
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 0.5rem;
}
.navbar > :not([hidden]) ~ :not([hidden]) {
@ -1024,10 +1104,12 @@ video {
}
.sidebar {
display: grid;
display: flex;
height: -moz-fit-content;
height: fit-content;
width: 12rem;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
gap: 0.5rem;
font-size: 0.875rem;
line-height: 1.25rem;
@ -1036,6 +1118,13 @@ video {
color: rgb(17 24 39 / var(--tw-text-opacity));
}
@media (min-width: 1024px) {
.sidebar {
width: 12rem;
flex-direction: column;
}
}
.sidebar a {
display: block;
width: 100%;
@ -1075,6 +1164,11 @@ video {
color: rgb(255 255 255 / var(--tw-text-opacity));
}
.breadcrumb {
margin-bottom: 1rem;
display: flex;
}
.healthchecks {
margin-top: 5rem;
display: grid;
@ -1119,10 +1213,25 @@ video {
background-color: rgb(239 68 68 / var(--tw-bg-opacity));
}
.hover\:text-blue-600:hover {
--tw-text-opacity: 1;
color: rgb(37 99 235 / var(--tw-text-opacity));
}
.hover\:underline:hover {
text-decoration-line: underline;
}
.focus\:border-blue-500:focus {
--tw-border-opacity: 1;
border-color: rgb(59 130 246 / var(--tw-border-opacity));
}
.focus\:outline-none:focus {
outline: 2px solid transparent;
outline-offset: 2px;
}
.focus\:ring-4:focus {
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(4px + var(--tw-ring-offset-width)) var(--tw-ring-color);
@ -1134,7 +1243,16 @@ video {
--tw-ring-color: rgb(147 197 253 / var(--tw-ring-opacity));
}
.focus\:ring-blue-500:focus {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(59 130 246 / var(--tw-ring-opacity));
}
@media (min-width: 640px) {
.sm\:w-auto {
width: auto;
}
.sm\:flex-row {
flex-direction: row;
}
@ -1160,6 +1278,12 @@ 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;
@ -1167,6 +1291,10 @@ video {
}
@media (min-width: 1024px) {
.lg\:grid-cols-\[1fr_100\%\] {
grid-template-columns: 1fr 100%;
}
.lg\:px-40 {
padding-left: 10rem;
padding-right: 10rem;
@ -1183,18 +1311,10 @@ video {
}
}
.rtl\:rotate-180:where([dir="rtl"], [dir="rtl"] *) {
--tw-rotate: 180deg;
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
.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\:text-gray-400 {
--tw-text-opacity: 1;
color: rgb(156 163 175 / var(--tw-text-opacity));
}
}

View file

@ -1,11 +1,12 @@
package components
type Page struct {
Path string
Title string
Path string
Title string
Breadcrumb string
}
type Base struct {
Page *Page
Pages []*Page
Navbar []*Page
NavbarActive *Page
}

View file

@ -1,9 +1,9 @@
{{define "base"}}
{{ $title := "" }}
{{ $path := "" }}
{{ if ne nil .Page }}
{{ $title = .Page.Title }}
{{ $path = .Page.Path }}
{{ if ne nil .NavbarActive }}
{{ $title = .NavbarActive.Title }}
{{ $path = .NavbarActive.Path }}
{{ end }}
<!DOCTYPE html>
@ -17,7 +17,7 @@
</head>
<body class="bg-gray-100">
<nav class="navbar">
{{range .Pages}}
{{range .Navbar}}
<a
{{$active := eq .Path $path }}
{{if $active}}aria-current="true"{{end}}
@ -31,8 +31,8 @@
{{template "main" .}}
</div>
<div class="container mx-auto">
<footer class="text-center text-gray-500 text-xs mt-8">
&copy; 2024 Zdravko - <a class="hover:underline" href="https://github.com/mentos1386/zdravko">Source</a>
<footer class="text-center text-gray-500 text-xs mt-8 mb-4">
&copy; 2024 Zdravko - <a class="hover:underline" href="https://github.com/mentos1386/zdravko">Open Source</a>
</footer>
<script src="/static/js/htmx.min.js"></script>
</body>

View file

@ -1,14 +1,14 @@
{{define "main"}}
{{ $title := "" }}
{{ $path := "" }}
{{ if ne nil .SettingsPage }}
{{ $title = .SettingsPage.Title }}
{{ $path = .SettingsPage.Path }}
{{ if ne nil .SettingsSidebarActive }}
{{ $title = .SettingsSidebarActive.Title }}
{{ $path = .SettingsSidebarActive.Path }}
{{ end }}
<div class="grid grid-cols-[1fr_100%] gap-8">
<div class="grid grid-cols-1 lg:grid-cols-[1fr_100%] gap-8">
<ul class="sidebar">
{{range .SettingsPages}}
{{range .SettingsSidebar}}
<li>
<a
{{$active := eq .Path $path }}
@ -20,8 +20,19 @@
</li>
{{end}}
</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">
{{ 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">
{{ .Breadcrumb }}
<svg aria-hidden="true" class="feather h-4 w-4 mx-1 text-gray-400 overflow-visible"><use href="/static/icons/feather-sprite.svg#chevron-right"/></svg>
</a>
</li>
{{ end }}
</ol>
</nav>
{{template "settings" .}}
</div>
</div>

View file

@ -2,6 +2,7 @@
{{ $description := "Healthchecks represent periodic checks of some HTTP or TCP service, to see if it's responding correctly to deterime if it's healthy or not." }}
{{ if eq .HealthchecksLength 0 }}
<section>
<div class="py-8 px-4 mx-auto max-w-screen-xl text-center lg:py-16">
<h1 class="mb-4 text-2xl font-extrabold tracking-tight leading-none text-gray-900 md:text-3xl lg:text-4xl">
@ -11,25 +12,28 @@
{{ $description }}
</p>
<div class="flex flex-col space-y-4 sm:flex-row sm:justify-center sm:space-y-0">
<a href="#" class="inline-flex justify-center items-center py-3 px-5 text-base font-medium text-center text-white rounded-lg bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300">
Create Healthcheck
<svg class="w-3.5 h-3.5 ms-2 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 10">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 5h12m0 0L9 1m4 4L9 9"/>
</svg>
<a href="/settings/healthchecks/create" class="inline-flex justify-center items-center py-3 px-5 text-base font-medium text-center text-white rounded-lg bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300">
Create First Healthcheck
<svg class="feather ml-1 h-5 w-5 overflow-visible"><use href="/static/icons/feather-sprite.svg#plus" /></svg>
</a>
</div>
</div>
</section>
{{ else }}
<div class="relative overflow-x-auto shadow-md sm:rounded-lg">
<table class="w-full text-sm text-left rtl:text-right text-gray-500">
<caption class="p-5 text-lg font-semibold text-left rtl:text-right text-gray-900 bg-white">
List of Healthchecks
<p class="mt-1 text-sm font-normal text-gray-500 dark:text-gray-400">
Healthchecks represent periodic checks of some HTTP or TCP service, to see if it's
responding correctly to deterime if it's healthy or not.
</p>
<div class="mt-1 flex">
<p class="mt-1 text-sm font-normal text-gray-500">
Healthchecks represent periodic checks of some HTTP or TCP service, to see if it's
responding correctly to deterime if it's healthy or not.
</p>
<a href="/settings/healthchecks/create" class="inline-flex justify-center items-center py-1 px-2 text-sm font-medium text-center text-white rounded-lg bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300">
Create New
<svg class="feather h-5 w-5 overflow-visible"><use href="/static/icons/feather-sprite.svg#plus" /></svg>
</a>
</div>
</caption>
<thead class="text-xs text-gray-700 uppercase bg-gray-50">
<tr>
@ -43,100 +47,35 @@
Status
</th>
<th scope="col" class="px-6 py-3">
Cron
Schedule
</th>
<th scope="col" class="px-6 py-3">
Action
</th>
</tr>
</thead>
{{range .Healthchecks}}
<tbody>
<tr class="odd:bg-white even:bg-gray-50">
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
Apple MacBook Pro 17"
{{.Name}}
</th>
<td class="px-6 py-4">
Silver
HTTP
</td>
<td class="px-6 py-4">
Laptop
OK
</td>
<td class="px-6 py-4">
$2999
{{.Schedule}}
</td>
<td class="px-6 py-4">
<a href="#" class="font-medium text-blue-600 hover:underline">Details</a>
</td>
</tr>
<tr class="odd:bg-white even:bg-gray-50">
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
Microsoft Surface Pro
</th>
<td class="px-6 py-4">
White
</td>
<td class="px-6 py-4">
Laptop PC
</td>
<td class="px-6 py-4">
$1999
</td>
<td class="px-6 py-4">
<a href="#" class="font-medium text-blue-600 hover:underline">Details</a>
</td>
</tr>
<tr class="odd:bg-white even:bg-gray-50 border-b">
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
Magic Mouse 2
</th>
<td class="px-6 py-4">
Black
</td>
<td class="px-6 py-4">
Accessories
</td>
<td class="px-6 py-4">
$99
</td>
<td class="px-6 py-4">
<a href="#" class="font-medium text-blue-600 hover:underline">Details</a>
</td>
</tr>
<tr class="odd:bg-white even:bg-gray-50 border-b">
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
Google Pixel Phone
</th>
<td class="px-6 py-4">
Gray
</td>
<td class="px-6 py-4">
Phone
</td>
<td class="px-6 py-4">
$799
</td>
<td class="px-6 py-4">
<a href="#" class="font-medium text-blue-600 hover:underline">Details</a>
</td>
</tr>
<tr class="odd:bg-white even:bg-gray-50 border-b">
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
Apple Watch 5
</th>
<td class="px-6 py-4">
Red
</td>
<td class="px-6 py-4">
Wearables
</td>
<td class="px-6 py-4">
$999
</td>
<td class="px-6 py-4">
<a href="#" class="font-medium text-blue-600 hover:underline">Details</a>
<a href="/settings/healthchecks/{{.ID}}" class="font-medium text-blue-600 hover:underline">Details</a>
</td>
</tr>
</tbody>
{{end}}
</table>
</div>
{{end}}
{{end}}

View file

@ -0,0 +1,24 @@
{{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>
{{end}}

View file

@ -0,0 +1,8 @@
{{define "settings"}}
<h1 class="mb-4 text-xl font-bold text-gray-900">
{{ .Healthcheck.Name }}
</h1>
{{ .Healthcheck.ID }}
{{ .Healthcheck.URL }}
{{ .Healthcheck.Schedule }}
{{end}}