core

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2025 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPlugin = errors.New("invalid plugin: missing HandleRequest")
View Source
var ErrNotFound = errors.New("barry: not found")
View Source
var ErrPluginNotFound = errors.New("plugin not found")
View Source
var ExecuteAPIFile = func(filePath string, req *http.Request, params map[string]string) ([]byte, error) {
	result, err := LoadPluginAndCallFunc(filePath, req, params)
	if err != nil && err != ErrPluginNotFound {
		return nil, err
	}
	if result != nil {
		return json.Marshal(result)
	}

	return ExecuteAPIFileWithSubprocessFunc(filePath, req, params)
}
View Source
var ExecuteAPIFileWithSubprocessFunc = ExecuteAPIFileWithSubprocess
View Source
var ExecuteServerFile = func(filePath string, req *http.Request, params map[string]string) (map[string]interface{}, error) {
	result, err := LoadPluginAndCallFunc(filePath, req, params)
	if err != nil && err != ErrPluginNotFound {
		return nil, err
	}
	if result != nil {
		return result, nil
	}

	return ExecuteServerFileWithSubprocessFunc(filePath, req, params)
}
View Source
var ExecuteServerFileWithSubprocessFunc = ExecuteServerFileWithSubprocess
View Source
var LoadConfig = func(path string) *Config {
	data, err := os.ReadFile(path)
	if err != nil {
		return &Config{
			OutputDir:    "./cache",
			CacheEnabled: false,
			DebugHeaders: false,
			DebugLogs:    false,
		}
	}

	var cfg Config
	yaml.Unmarshal(data, &cfg)

	if cfg.OutputDir == "" {
		cfg.OutputDir = "./cache"
	}

	return &cfg
}
View Source
var LoadPluginAndCallFunc = LoadPluginAndCall
View Source
var NewLiveReloader = func() LiveReloaderInterface {
	return &LiveReloader{
		clients: make(map[*websocket.Conn]bool),
		upgrader: websocket.Upgrader{
			CheckOrigin: func(r *http.Request) bool {
				return true
			},
		},
	}
}
View Source
var NewRouter = func(config Config, ctx RuntimeContext) http.Handler {
	r := &Router{
		config:   config,
		env:      ctx.Env,
		onReload: ctx.OnReload,
	}

	var wg sync.WaitGroup
	wg.Add(3)
	go func() {
		defer wg.Done()
		r.loadRoutes()
	}()
	go func() {
		defer wg.Done()
		r.loadComponentFiles()
	}()
	go func() {
		defer wg.Done()
		r.loadApiRoutes()
	}()
	wg.Wait()

	if ctx.EnableWatch {
		go r.watchEverything()
	}

	return r
}
View Source
var SaveCachedHTMLFunc = SaveCachedHTML

Functions

func BarryTemplateFuncs added in v0.1.9

func BarryTemplateFuncs(env, cacheDir string) template.FuncMap

func ExecuteAPIFileWithSubprocess added in v0.5.0

func ExecuteAPIFileWithSubprocess(filePath string, req *http.Request, params map[string]string) ([]byte, error)

func ExecuteServerFileWithSubprocess added in v0.5.0

func ExecuteServerFileWithSubprocess(filePath string, req *http.Request, params map[string]string) (map[string]interface{}, error)

func GetCachedHTML

func GetCachedHTML(config Config, route, ext string) ([]byte, bool)

func IsNotFoundError added in v0.1.11

func IsNotFoundError(err error) bool

func LoadPluginAndCall added in v0.5.0

func LoadPluginAndCall(filePath string, req *http.Request, params map[string]string) (map[string]interface{}, error)

func MinifyAsset added in v0.1.9

func MinifyAsset(env, path string, cacheDir string) string

func SaveCachedHTML

func SaveCachedHTML(config Config, routeKey, ext string, data []byte) error

Types

type ApiRoute added in v0.4.0

type ApiRoute struct {
	Method       string
	URLPattern   *regexp.Regexp
	ParamKeys    []string
	ParamRawKeys []string
	ServerPath   string
	FilePath     string
}

type Config

type Config struct {
	OutputDir    string `yaml:"outputDir"`
	CacheEnabled bool   `yaml:"cache"`
	DebugHeaders bool   `yaml:"debugHeaders"`
	DebugLogs    bool   `yaml:"debugLogs"`
}

type ExecContext

type ExecContext struct {
	ImportPath string
	Params     map[string]string
	Method     string
	URL        string
	Headers    map[string][]string
	Body       string
	Host       string
	RemoteAddr string
}

type LiveReloader

type LiveReloader struct {
	// contains filtered or unexported fields
}

func (*LiveReloader) BroadcastReload

func (lr *LiveReloader) BroadcastReload()

func (*LiveReloader) Handler

func (lr *LiveReloader) Handler(w http.ResponseWriter, r *http.Request)

type LiveReloaderInterface added in v0.3.2

type LiveReloaderInterface interface {
	BroadcastReload()
	Handler(http.ResponseWriter, *http.Request)
}

type Route

type Route struct {
	URLPattern   *regexp.Regexp
	ParamKeys    []string
	ParamRawKeys []string
	HTMLPath     string
	ServerPath   string
	FilePath     string
}

type Router

type Router struct {
	// contains filtered or unexported fields
}

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

type RuntimeContext

type RuntimeContext struct {
	Env         string
	EnableWatch bool
	OnReload    func()
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL