2022-11-13 11:55:10 -05:00
|
|
|
// common contains common functionality for blasphem.
|
2022-09-25 11:42:36 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2022-12-19 13:09:01 -05:00
|
|
|
"github.com/labstack/echo/v4"
|
2022-09-25 11:42:36 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2022-12-19 19:24:01 -05:00
|
|
|
// this symbol overriden by linker args
|
|
|
|
var Version = "undefined"
|
|
|
|
|
2022-09-25 11:42:36 -04:00
|
|
|
const (
|
2022-11-13 11:55:10 -05:00
|
|
|
// AppName is the name of the application.
|
2022-09-25 11:42:36 -04:00
|
|
|
AppName = "blasphem"
|
|
|
|
)
|
|
|
|
|
|
|
|
type cmdOptions interface {
|
|
|
|
Options(*cobra.Command, []string) error
|
|
|
|
Execute() error
|
|
|
|
}
|
|
|
|
|
2022-11-20 08:49:24 -05:00
|
|
|
func AppNamePtr() *string {
|
|
|
|
s := AppName
|
|
|
|
return &s
|
|
|
|
}
|
|
|
|
|
|
|
|
func IntPtr(i int) *int { return &i }
|
|
|
|
|
2022-11-13 11:55:10 -05:00
|
|
|
// RunE is a convenience function for use with cobra.
|
2022-09-25 11:42:36 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2022-12-19 13:09:01 -05:00
|
|
|
|
|
|
|
func NoCache(c echo.Context) echo.Context {
|
|
|
|
c.Response().Header().Set("Cache-Control", "no-store")
|
|
|
|
c.Response().Header().Set("Pragma", "no-cache")
|
|
|
|
return c
|
|
|
|
}
|