GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — cli/calls.go at master · appoxy/cli Expand file tree/ Copy pathcalls.goMore file actions 99 lines (91 loc) · 2.29 KB / Copy pathcalls.goFile metadata and controls99 lines (91 loc) · 2.29 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 package main import ( "context" "fmt" client "github.com/fnproject/cli/client" fnclient "github.com/funcy/functions_go/client" apicall "github.com/funcy/functions_go/client/call" "github.com/funcy/functions_go/models" "github.com/urfave/cli" ) type callsCmd struct { client *fnclient.Functions } func calls() cli.Command { c := callsCmd{client: client.APIClient()} return cli.Command{ Name: "calls", Usage: "manage function calls for apps", Subcommands: []cli.Command{ { Name: "get", Aliases: []string{"g"}, Usage: "get function call info per app", ArgsUsage: "<app> <call-id>", Action: c.get, }, { Name: "list", Aliases: []string{"l"}, Usage: "list all calls for specific app / route route is optional", ArgsUsage: "<app> [route]", Action: c.list, }, }, } } func printCalls(calls []*models.Call) { for _, call := range calls { fmt.Println(fmt.Sprintf( "ID: %v\n"+ "App: %v\n"+ "Route: %v\n"+ "Created At: %v\n"+ "Started At: %v\n"+ "Completed At: %v\n"+ "Status: %v\n", call.ID, call.AppName, call.Path, call.CreatedAt, call.StartedAt, call.CompletedAt, call.Status)) } } func (call *callsCmd) get(ctx *cli.Context) error { app, callID := ctx.Args().Get(0), ctx.Args().Get(1) params := apicall.GetAppsAppCallsCallParams{ Call: callID, App: app, Context: context.Background(), } resp, err := call.client.Call.GetAppsAppCallsCall(¶ms) if err != nil { switch e := err.(type) { case *apicall.GetAppsAppCallsCallNotFound: return fmt.Errorf("error: %v", e.Payload.Error.Message) default: return fmt.Errorf("unexpected error: %v", err) } } printCalls([]*models.Call{resp.Payload.Call}) return nil } func (call *callsCmd) list(ctx *cli.Context) error { app := ctx.Args().Get(0) params := apicall.GetAppsAppCallsParams{ App: app, Context: context.Background(), } if ctx.Args().Get(1) != "" { route := ctx.Args().Get(1) params.Route = &route } resp, err := call.client.Call.GetAppsAppCalls(¶ms) if err != nil { switch e := err.(type) { case *apicall.GetCallsCallNotFound: return fmt.Errorf("error: %v", e.Payload.Error.Message) default: return fmt.Errorf("unexpected error: %v", err) } } printCalls(resp.Payload.Calls) return nil } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |