Cleaned up methods
This commit is contained in:
parent
09c1bd44c9
commit
a57ffd6ece
@ -8,7 +8,8 @@ import (
|
|||||||
"github.com/uptrace/bun/driver/pgdriver"
|
"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)))
|
sqldb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(dsn)))
|
||||||
return bun.NewDB(sqldb, pgdialect.New())
|
r := PostgresClient{bun.NewDB(sqldb, pgdialect.New())}
|
||||||
|
return r
|
||||||
}
|
}
|
||||||
|
5
interfaces.go
Normal file
5
interfaces.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
type Endpoint interface {
|
||||||
|
IsEndpoint() bool
|
||||||
|
}
|
17
main.go
17
main.go
@ -1,16 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tofu Provider is the goal
|
// Tofu Provider is the goal
|
||||||
// Data Sources first
|
// Data Sources first
|
||||||
// Resources later
|
// Resources later
|
||||||
|
|
||||||
var users []UserModel
|
//var users []UserModel
|
||||||
var ssh_keys []SSHKeyModel
|
//var ssh_keys []SSHKeyModel
|
||||||
|
|
||||||
//var servers []Server
|
//var servers []Server
|
||||||
//var server_definitions []ServerDefinition
|
//var server_definitions []ServerDefinition
|
||||||
//var manifests []Manifest
|
//var manifests []Manifest
|
||||||
@ -19,14 +18,16 @@ var ssh_keys []SSHKeyModel
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var (
|
var (
|
||||||
ctx = context.Background()
|
// ctx = context.Background()
|
||||||
dsn = "postgres://postgres:Initial1@localhost:15432/anvil?sslmode=disable"
|
dsn = "postgres://postgres:Initial1@localhost:15432/anvil?sslmode=disable"
|
||||||
// dsn := "unix://user:pass@dbname/var/run/postgresql/.s.PGSQL.5432"
|
// dsn := "unix://user:pass@dbname/var/run/postgresql/.s.PGSQL.5432"
|
||||||
)
|
)
|
||||||
// Calling PostgresClient as an instance method as per:
|
anvil := new(Anvil)
|
||||||
// https://stackoverflow.com/questions/38666404/not-enough-arguments-in-call-to-method-expression
|
anvil.AddStriker(Striker{})
|
||||||
anvildb := OpenDB(dsn)
|
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.
|
// Turn these into funcs with error handling, logging, return vals etc.
|
||||||
// if usererr := anvildb.NewSelect().
|
// if usererr := anvildb.NewSelect().
|
||||||
// // Turning *User into an interface &User{}
|
// // Turning *User into an interface &User{}
|
||||||
|
17
methods.go
Normal file
17
methods.go
Normal file
@ -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)
|
||||||
|
}
|
10
types.go
10
types.go
@ -1,9 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/uptrace/bun"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,15 +25,17 @@ type SSHClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PostgresClient struct {
|
type PostgresClient struct {
|
||||||
*sql.DB
|
*bun.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
type Striker struct {
|
type Striker struct {
|
||||||
FQDN string
|
FQDN string
|
||||||
|
Endpoints []Endpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
type Host struct {
|
type Host struct {
|
||||||
FQDN string
|
FQDN string
|
||||||
|
Endpoints []Endpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
type BMC struct {
|
type BMC struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user