Skip to content

Commit c8fdb8f

Browse files
committed
feat(run): Print out the Api Endpoints
1 parent 726004d commit c8fdb8f

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

pkg/cmd/run/root.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ var runCmd = &cobra.Command{
122122

123123
fmt.Println("Local running, use ctrl-C to stop")
124124

125+
type apiendpoint struct {
126+
Api string `yaml:"api"`
127+
Endpoint string `yaml:"endpoint"`
128+
}
129+
apis := []apiendpoint{}
130+
131+
for a := range s.ApiDocs {
132+
apis = append(apis, apiendpoint{Api: a, Endpoint: fmt.Sprintf("http://127.0.0.1:9001/apis/%s", a)})
133+
}
134+
if len(apis) == 0 {
135+
// if we have a nitric.yaml then ApiDocs will be empty
136+
for a := range s.Apis {
137+
apis = append(apis, apiendpoint{Api: a, Endpoint: fmt.Sprintf("http://127.0.0.1:9001/apis/%s", a)})
138+
}
139+
}
140+
output.Print(apis)
141+
125142
select {
126143
case membraneError := <-memerr:
127144
fmt.Println(errors.WithMessage(membraneError, "membrane error, exiting"))

pkg/output/format.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,26 @@ func printList(object interface{}, out io.Writer) {
124124
tab.SetOutputMirror(out)
125125

126126
t := reflect.TypeOf(object)
127-
tab.AppendHeader(namesFrom(t.Elem()))
127+
names := namesFrom(t.Elem())
128+
if len(names) > 0 {
129+
tab.AppendHeader(names)
130+
}
128131
rows := []table.Row{}
129132
v := reflect.ValueOf(object)
133+
130134
for i := 0; i < v.Len(); i++ {
131-
if v.Index(i).Kind() == reflect.Struct {
135+
switch v.Index(i).Kind() {
136+
case reflect.Struct:
132137
row := table.Row{}
133138
for fi := 0; fi < v.Index(i).NumField(); fi++ {
134139
row = append(row, v.Index(i).Field(fi))
135140
}
136141
rows = append(rows, row)
142+
case reflect.Slice, reflect.Array, reflect.Func, reflect.Chan, reflect.Interface, reflect.Map:
143+
// not yet supported
144+
default:
145+
// simple types
146+
rows = append(rows, table.Row{v.Index(i)})
137147
}
138148
}
139149
tab.AppendRows(rows)

pkg/run/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (s *WorkerPoolEventService) Publish(topic string, event *events.NitricEvent
6565
Event: evt,
6666
})
6767

68-
fmt.Println(fmt.Sprintf("Publishing event to: %s", targets))
68+
fmt.Printf("Publishing event to: %s\n", targets)
6969
for _, target := range targets {
7070
err = target.HandleEvent(evt)
7171
if err != nil {

pkg/run/run.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@ type LocalServices interface {
4141
}
4242

4343
type LocalServicesStatus struct {
44-
Running bool `yaml:"running"`
45-
RunDir string `yaml:"runDir"`
46-
GatewayAddress string `yaml:"gatewayAddress"`
47-
MembraneAddress string `yaml:"membraneAddress"`
48-
MinioContainerID string `yaml:"minioContainerID"`
49-
MinioEndpoint string `yaml:"minioEndpoint"`
44+
RunDir string `yaml:"runDir"`
45+
GatewayAddress string `yaml:"gatewayAddress"`
46+
MembraneAddress string `yaml:"membraneAddress"`
47+
MinioEndpoint string `yaml:"minioEndpoint"`
5048
}
5149

5250
type localServices struct {
@@ -62,7 +60,6 @@ func NewLocalServices(stackName, stackPath string) LocalServices {
6260
stackName: stackName,
6361
stackPath: stackPath,
6462
status: &LocalServicesStatus{
65-
Running: false,
6663
RunDir: path.Join(utils.NitricRunDir(), stackName),
6764
GatewayAddress: nitric_utils.GetEnv("GATEWAY_ADDRESS", ":9001"),
6865
MembraneAddress: net.JoinHostPort("localhost", "50051"),
@@ -76,13 +73,12 @@ func (l *localServices) Stop() error {
7673
}
7774

7875
func (l *localServices) Running() bool {
79-
l.status.Running = false
8076
conn, err := net.DialTimeout("tcp", net.JoinHostPort("0.0.0.0", "50051"), time.Second)
8177
if err == nil && conn != nil {
8278
defer conn.Close()
83-
l.status.Running = true
79+
return true
8480
}
85-
return l.status.Running
81+
return false
8682
}
8783

8884
func (l *localServices) Status() *LocalServicesStatus {
@@ -101,7 +97,6 @@ func (l *localServices) Start() error {
10197
if err != nil {
10298
return err
10399
}
104-
l.status.MinioContainerID = l.mio.cid
105100
l.status.MinioEndpoint = fmt.Sprintf("localhost:%d", l.mio.GetApiPort())
106101

107102
// Connect dev storage

0 commit comments

Comments
 (0)