Cleaned up methods

data-work
Mike Holloway 3 months ago
parent 09c1bd44c9
commit a57ffd6ece
  1. 5
      functions.go
  2. 5
      interfaces.go
  3. 17
      main.go
  4. 17
      methods.go
  5. 6
      types.go

@ -8,7 +8,8 @@ import (
"github.com/uptrace/bun/driver/pgdriver"
)
func OpenDB(dsn string) *sql.DB {
func OpenDB(dsn string) PostgresClient {
sqldb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(dsn)))
return bun.NewDB(sqldb, pgdialect.New())
r := PostgresClient{bun.NewDB(sqldb, pgdialect.New())}
return r
}

@ -0,0 +1,5 @@
package main
type Endpoint interface {
IsEndpoint() bool
}

@ -1,16 +1,15 @@
package main
import (
"context"
"fmt"
)
// Tofu Provider is the goal
// Data Sources first
// Resources later
var users []UserModel
var ssh_keys []SSHKeyModel
//var users []UserModel
//var ssh_keys []SSHKeyModel
//var servers []Server
//var server_definitions []ServerDefinition
//var manifests []Manifest
@ -19,14 +18,16 @@ var ssh_keys []SSHKeyModel
func main() {
var (
ctx = context.Background()
// ctx = context.Background()
dsn = "postgres://postgres:Initial1@localhost:15432/anvil?sslmode=disable"
// dsn := "unix://user:pass@dbname/var/run/postgresql/.s.PGSQL.5432"
)
// Calling PostgresClient as an instance method as per:
// https://stackoverflow.com/questions/38666404/not-enough-arguments-in-call-to-method-expression
anvildb := OpenDB(dsn)
anvil := new(Anvil)
anvil.AddStriker(Striker{})
anvil.Strikers[0].SetFQDN("mh-striker01.libre.audio")
anvil.Strikers[0].AddEndpoint(PostgresClient(OpenDB(dsn)))
fmt.Printf("%s\n", anvil.Strikers[0])
// Turn these into funcs with error handling, logging, return vals etc.
// if usererr := anvildb.NewSelect().
// // Turning *User into an interface &User{}

@ -0,0 +1,17 @@
package main
func (p PostgresClient) IsEndpoint() bool {
return true
}
func (s *Striker) SetFQDN(fqdn string) {
s.FQDN = fqdn
}
func (s *Striker) AddEndpoint(e Endpoint) {
s.Endpoints = append(s.Endpoints, e)
}
func (a *Anvil) AddStriker(s Striker) {
a.Strikers = append(a.Strikers, s)
}

@ -1,9 +1,9 @@
package main
import (
"database/sql"
"net/http"
"github.com/uptrace/bun"
"golang.org/x/crypto/ssh"
)
@ -25,15 +25,17 @@ type SSHClient struct {
}
type PostgresClient struct {
*sql.DB
*bun.DB
}
type Striker struct {
FQDN string
Endpoints []Endpoint
}
type Host struct {
FQDN string
Endpoints []Endpoint
}
type BMC struct {

Loading…
Cancel
Save