blasphem/internal/common/common.go
2022-12-19 13:09:01 -05:00

48 lines
926 B
Go

// common contains common functionality for blasphem.
package common
import (
"github.com/labstack/echo/v4"
"github.com/spf13/cobra"
)
const (
// AppName is the name of the application.
AppName = "blasphem"
)
type cmdOptions interface {
Options(*cobra.Command, []string) error
Execute() error
}
func AppNamePtr() *string {
s := AppName
return &s
}
func IntPtr(i int) *int { return &i }
// RunE is a convenience function for use with cobra.
func RunE(c cmdOptions) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
err := c.Options(cmd, args)
if err != nil {
cmd.SilenceUsage = true
return err
}
err = c.Execute()
if err != nil {
cmd.SilenceUsage = true
}
return err
}
}
func NoCache(c echo.Context) echo.Context {
c.Response().Header().Set("Cache-Control", "no-store")
c.Response().Header().Set("Pragma", "no-cache")
return c
}