Add database stub
This commit is contained in:
parent
f23f7226f6
commit
6d64c86577
5 changed files with 49 additions and 4 deletions
|
@ -10,9 +10,10 @@ import (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
Database string
|
||||
UnixSocket string
|
||||
Service []scanner.ServiceConfig
|
||||
Matrix MatrixConfig
|
||||
UnixSocket string
|
||||
}
|
||||
|
||||
type MatrixConfig struct {
|
||||
|
|
|
@ -1,3 +1,36 @@
|
|||
package core
|
||||
|
||||
// todo
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.exozy.me/exozyme/status/scanner"
|
||||
)
|
||||
|
||||
type Row struct {
|
||||
time time.Time
|
||||
data scanner.ServiceStatus
|
||||
}
|
||||
|
||||
type Database struct {
|
||||
// todo
|
||||
}
|
||||
|
||||
func OpenDatabase(path string) (*Database, error) {
|
||||
// todo
|
||||
// if path == "" {
|
||||
// return nil, fmt.Errorf("database path is empty. did you set it in config file?")
|
||||
// }
|
||||
return &Database{}, nil
|
||||
}
|
||||
|
||||
// get all records after some time (`cutoff`)
|
||||
func (db *Database) QueryAllAfter(url string, cutoff time.Time) ([]Row, error) {
|
||||
// todo
|
||||
return []Row{}, nil
|
||||
}
|
||||
|
||||
// store records with current
|
||||
func (db *Database) RememberNow(scanner.ServiceStatusBatch) error {
|
||||
// todo
|
||||
return nil
|
||||
}
|
||||
|
|
8
main.go
8
main.go
|
@ -57,7 +57,7 @@ func rootPage(w http.ResponseWriter, r *http.Request) {
|
|||
// get service status'
|
||||
timeout := time.Second
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
data := scanner.TestMultipleServices(ctx, config.Service)
|
||||
data := scanner.TestServiceBatch(ctx, config.Service)
|
||||
cancel()
|
||||
|
||||
// don't uncomment this in production. verbose
|
||||
|
@ -79,6 +79,7 @@ func removeFile(path string) {
|
|||
}
|
||||
|
||||
var config *core.Config
|
||||
var dbm *core.Database
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
|
@ -87,6 +88,11 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
dbm, err = core.OpenDatabase(config.Database)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
http.HandleFunc("/", rootPage)
|
||||
|
||||
// serve public folder from embedfs
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
# unixSocket = "/srv/http/pages/status"
|
||||
# database = "/opt/status-config/db"
|
||||
database = "/tmp/exozyme-status-test-db"
|
||||
|
||||
service = [
|
||||
{ description = "exozy.me", url = "https://exozy.me" },
|
||||
{ description = "drgns.space", url = "https://drgns.space" },
|
||||
|
|
|
@ -68,7 +68,9 @@ func TestService(service ServiceConfig, ctx context.Context) ServiceStatus {
|
|||
}
|
||||
}
|
||||
|
||||
func TestMultipleServices(ctx Context, services []ServiceConfig) []ServiceStatus {
|
||||
type ServiceStatusBatch []ServiceStatus
|
||||
|
||||
func TestServiceBatch(ctx Context, services []ServiceConfig) ServiceStatusBatch {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
var data []ServiceStatus = make([]ServiceStatus, len(services))
|
||||
|
|
Loading…
Reference in a new issue