Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var LsServerCmd = &cobra.Command{ Use: "ls", Short: "List a server's commands", Run: func(cmd *cobra.Command, args []string) { server, err := cmd.Flags().GetString("server") cobra.CheckErr(err) resp, err := http.Get(server + "/api/commands") cobra.CheckErr(err) defer func(Body io.ReadCloser) { err := Body.Close() if err != nil { log.Error().Err(err).Msg("Failed to close response body") } }(resp.Body) body, err := io.ReadAll(resp.Body) cobra.CheckErr(err) // Unmarshal the response JSON into a slice of CommandDescription structs var cmds []map[string]interface{} err = json.Unmarshal(body, &cmds) cobra.CheckErr(err) gp, err := cli.CreateGlazedProcessorFromCobra(cmd) cobra.CheckErr(err) for _, cmd := range cmds { err = gp.ProcessInputObject(cmd) cobra.CheckErr(err) } s, err := gp.OutputFormatter().Output() cobra.CheckErr(err) fmt.Print(s) }, }
View Source
var ServeCmd = &cobra.Command{ Use: "serve", Short: "Starts the server", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { _, err := cmd.Flags().GetUint16("port") cobra.CheckErr(err) serverOptions := []pkg.ServerOption{} dev, _ := cmd.Flags().GetBool("dev") templateDir, err := cmd.Flags().GetString("template-dir") cobra.CheckErr(err) if dev { log.Info(). Str("assetsDir", "pkg/web/dist"). Str("templateDir", "pkg/web/src/templates"). Msg("Using assets from disk") serverOptions = append(serverOptions, pkg.WithStaticPaths(pkg.NewStaticPath(http.FS(os.DirFS("pkg/web/dist")), "/dist")), pkg.WithPrependTemplateLookups(render.LookupTemplateFromDirectory("pkg/web/src/templates")), ) cobra.CheckErr(err) } if templateDir != "" { if dev { serverOptions = append(serverOptions, pkg.WithPrependTemplateLookups(render.LookupTemplateFromDirectory(templateDir))) } else { lookup, err := render.LookupTemplateFromFS(os.DirFS(templateDir), ".", "**/*.tmpl.*") cobra.CheckErr(err) serverOptions = append(serverOptions, pkg.WithPrependTemplateLookups(lookup)) } } s, _ := pkg.NewServer(serverOptions...) s.Router.GET("/api/example", s.HandleSimpleQueryCommand(NewExampleCommand())) s.Router.POST("/api/example", s.HandleSimpleFormCommand(NewExampleCommand())) ctx, cancel := context.WithCancel(context.Background()) defer cancel() go func() { err := helpers.CancelOnSignal(ctx, os.Interrupt, cancel) if err != nil && err != context.Canceled { fmt.Println(err) } }() err = s.Run(ctx) cobra.CheckErr(err) }, }
Functions ¶
This section is empty.
Types ¶
type ExampleCommand ¶
type ExampleCommand struct {
// contains filtered or unexported fields
}
func NewExampleCommand ¶
func NewExampleCommand() *ExampleCommand
func (*ExampleCommand) Description ¶
func (e *ExampleCommand) Description() *cmds.CommandDescription
func (*ExampleCommand) Run ¶
func (e *ExampleCommand) Run( ctx context.Context, parsedLayers map[string]*layers.ParsedParameterLayer, ps map[string]interface{}, gp cmds.Processor, ) error
func (*ExampleCommand) RunFromParka ¶
func (e *ExampleCommand) RunFromParka(c *gin.Context, parsedLayers map[string]*layers.ParsedParameterLayer, ps map[string]interface{}, gp *cmds.GlazeProcessor) error
Click to show internal directories.
Click to hide internal directories.