github.com/omnigres/cli@v0.1.4/orb/cluster.go (about) 1 package orb 2 3 import ( 4 "context" 5 "database/sql" 6 "fmt" 7 "io" 8 "net" 9 ) 10 11 type OrbOptions struct { 12 *Config 13 Path string 14 } 15 16 type OrbStartEventListener struct { 17 Started func(cluster OrbCluster) 18 Ready func(cluster OrbCluster) 19 } 20 21 type OrbRunEventListener struct { 22 OutputHandler func(cluster OrbCluster, reader io.Reader) 23 Stopped func(cluster OrbCluster) 24 } 25 26 type OrbClusterStartOptions struct { 27 Attachment struct { 28 ShouldAttach bool 29 Listeners []OrbRunEventListener 30 } 31 AutoRemove bool 32 Listeners []OrbStartEventListener 33 Runfile bool 34 } 35 36 type OrbCluster interface { 37 Configure(options OrbOptions) error 38 Start(ctx context.Context, options OrbClusterStartOptions, user *string, entryPoint []string) error 39 StartWithCurrentUser(ctx context.Context, options OrbClusterStartOptions) error 40 Stop(ctx context.Context) error 41 Endpoints(ctx context.Context) ([]Endpoint, error) 42 Connect(ctx context.Context, database ...string) (*sql.DB, error) 43 ConnectPsql(ctx context.Context, database ...string) error 44 Close() error 45 Config() *Config 46 } 47 48 type Endpoint struct { 49 Database string 50 net.IP 51 Port int 52 Protocol string 53 } 54 55 func (e *Endpoint) String() (s string) { 56 switch e.Protocol { 57 case "HTTP": 58 s = fmt.Sprintf("http://%s:%d", e.IP.String(), e.Port) 59 case "Postgres": 60 s = fmt.Sprintf("postgres://omnigres:omnigres@%s:%d/%s", e.IP.String(), e.Port, e.Database) 61 default: 62 s = fmt.Sprintf("%s:%d", e.IP.String(), e.Port) 63 } 64 return 65 }