Skip to content

Commit 302a5aa

Browse files
committed
list endpoints
1 parent 26ec909 commit 302a5aa

File tree

6 files changed

+94
-0
lines changed

6 files changed

+94
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Usage:
1212
Available Commands:
1313
help Help about any command
1414
start Start local functions lambda
15+
endpoints List endpoints functions lambda
1516

1617
Flags:
1718
-h, --help help for lambda-local

bin/darwin/lambda-local

4.61 KB
Binary file not shown.

bin/linux/lambda-local

-7.33 KB
Binary file not shown.

cmd/endpoints.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright © 2019 NAME HERE <EMAIL ADDRESS>
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package cmd
17+
18+
import (
19+
"github.com/lbernardo/lambda-local/controller"
20+
"github.com/spf13/cobra"
21+
)
22+
23+
var YamlConfig string
24+
25+
// endpointsCmd represents the endpoints command
26+
var endpointsCmd = &cobra.Command{
27+
Use: "endpoints",
28+
Short: "List endpoints API Gateway",
29+
Long: `List endpoints API Gateway`,
30+
Run: func(cmd *cobra.Command, args []string) {
31+
ExecuteCmdEndpoints(cmd, args)
32+
},
33+
}
34+
35+
func init() {
36+
rootCmd.AddCommand(endpointsCmd)
37+
endpointsCmd.PersistentFlags().StringVar(&YamlConfig, "yaml", "serverless.yml", "File yaml serverless.yml [default serverless.yml]")
38+
}
39+
40+
func ExecuteCmdEndpoints(cmd *cobra.Command, args []string) {
41+
endController := controller.NewEndpointsController(YamlConfig, "127.0.0.1", "3000")
42+
endController.ListEndpoints()
43+
}

cmd/start.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ func ExecuteCmdStart(cmd *cobra.Command, args []string) {
3939
Volume: Volume,
4040
Network: Network,
4141
}
42+
ep := controller.EndpointsController{
43+
Host: Host,
44+
Port: Port,
45+
Yaml: Yaml,
46+
}
4247
se.StartConfig()
48+
49+
ep.ListEndpoints()
50+
4351
se.StartServer()
4452
}

controller/endpoints.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package controller
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"strings"
7+
8+
"github.com/lbernardo/lambda-local/model"
9+
)
10+
11+
type EndpointsController struct {
12+
Yaml string
13+
Host string
14+
Port string
15+
JSON model.Serverless
16+
}
17+
18+
func NewEndpointsController(yaml string, host string, port string) *EndpointsController {
19+
return &EndpointsController{
20+
Yaml: yaml,
21+
Host: host,
22+
Port: port,
23+
}
24+
}
25+
26+
func (ec *EndpointsController) ContentYaml() {
27+
content, err := ReadYaml(ec.Yaml)
28+
if err != nil {
29+
panic(err)
30+
}
31+
json.Unmarshal(content, &ec.JSON)
32+
}
33+
34+
func (ec *EndpointsController) ListEndpoints() {
35+
ec.ContentYaml()
36+
fmt.Println("Endpoints")
37+
for _, function := range ec.JSON.Functions {
38+
for _, event := range function.Events {
39+
fmt.Printf("- http://%v:%v/%v [\033[01;32m%v\033[0m]\n\n", ec.Host, ec.Port, event.HttpEvent.Path, strings.ToUpper(event.HttpEvent.Method))
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)