funcadmin

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

funcadmin

Go Report Card PkgGoDev

License

This project is licensed under the MIT License. You can find a copy of the license at LICENSE.

Introduction

Admin interface for github.com/dracory/funcstore. Provides a ready-to-use admin panel for managing serverless functions and groups: dashboard, function manager, function editor (source + versions), function invoke tester, and group management.

Modeled after github.com/dracory/shopadmin — same folder-per-controller pattern, same UiConfig/UiBase conventions, same AdminOptions/New()/Handle() entry point.

Features

  • Dashboard — overview of functions and groups
  • Function management — create, update, delete functions with alias, runtime, timeout, metadata
  • Source versions — view saved versions and restore previous sources
  • Function invoke — test-run functions with JSON input from the UI
  • Group management — hierarchical groups with create/update/delete
  • Custom layouts — bring your own layout via FuncLayout
  • Bootstrap + Vue CDN — default UI works out of the box

Installation

go get github.com/dracory/funcadmin

Quick Start

package main

import (
    "log/slog"
    "net/http"
    "os"

    "github.com/dracory/funcadmin"
    "github.com/dracory/funcstore"
)

func main() {
    store, err := funcstore.NewStore(funcstore.StoreOptions{
        DB:                 yourDB,
        Driver:             "sqlite",
        Runtimes:           []funcstore.Runtime{funcstore.NewGojaRuntime()},
        AutomigrateEnabled: true,
    })
    if err != nil {
        log.Fatal(err)
    }

    admin, err := funcadmin.New(funcadmin.AdminOptions{
        Store:         store,
        Logger:        slog.New(slog.NewTextHandler(os.Stderr, nil)),
        AdminHomeURL:  "/admin",
        FaaSAdminURL:  "/admin/faas",
    })
    if err != nil {
        log.Fatal(err)
    }

    http.Handle("/admin/faas", admin)
    http.ListenAndServe(":8080", nil)
}

Integration with a Router

funcadmin.AdminInterface exposes Handle(w, r), which is an http.HandlerFunc-compatible method. Wire it into any router that accepts standard http.Handler:

// stdlib
mux.Handle("/admin/faas", http.HandlerFunc(admin.Handle))

Requests are dispatched by the ?controller= query parameter (dashboard, function-manager, function-update, function-invoke, group-manager, group-update). An empty or unknown controller falls back to the dashboard.

Custom Layout

By default, funcadmin renders a bare-bones HTML page with Bootstrap and Vue from CDN. To embed the admin inside your own layout (branding, menus, etc.), provide FuncLayout:

admin, _ := funcadmin.New(funcadmin.AdminOptions{
    Store:  store,
    Logger: logger,
    FuncLayout: func(w http.ResponseWriter, r *http.Request, title, body string, opts struct {
        Styles     []string
        StyleURLs  []string
        Scripts    []string
        ScriptURLs []string
    }) string {
        return myLayout(w, r, title, body, opts)
    },
})

Authentication

Provide AuthUserID to gate the whole admin behind your auth system:

AuthUserID: func(r *http.Request) string {
    user := session.GetAuthUser(r)
    if user == nil {
        return ""
    }
    return user.GetID()
},

If it returns an empty string, the request is redirected to AdminHomeURL. If AuthUserID is nil, no auth check is performed.

Testing

go test ./...

Documentation

Overview

Package funcadmin provides a standalone admin interface for the funcstore package, following the folder-per-controller pattern. Each controller is in its own subfolder and handles its own views and AJAX data.

This module is modeled on github.com/dracory/blogadmin.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrStoreRequired is returned when Store is not provided
	ErrStoreRequired = errors.New("FaaS store is required")

	// ErrLoggerRequired is returned when Logger is not provided
	ErrLoggerRequired = errors.New("logger is required")
)

Common errors

Functions

This section is empty.

Types

type AdminInterface

type AdminInterface interface {
	Handle(w http.ResponseWriter, r *http.Request)
}

AdminInterface defines the interface for the FaaS admin

func New

func New(opts AdminOptions) (AdminInterface, error)

New creates a new FaaS admin instance. Returns ErrStoreRequired if Store is nil, ErrLoggerRequired if Logger is nil.

type AdminOptions

type AdminOptions struct {
	// Store is the funcstore.StoreInterface (required)
	Store funcstore.StoreInterface

	// Logger is required
	Logger *slog.Logger

	// FuncLayout is an optional function to render the admin interface
	// inside your own layout (branding, menus, etc.). It receives the
	// request and response writer so the host project can access request
	// context (auth user, locale, etc.) when rendering the layout.
	FuncLayout func(w http.ResponseWriter, r *http.Request, title string, body string, options struct {
		Styles     []string
		StyleURLs  []string
		Scripts    []string
		ScriptURLs []string
	}) string

	// AdminHomeURL is the URL for the admin home page (default: "/admin")
	AdminHomeURL string

	// FaaSAdminURL is the base URL for FaaS admin (default: "/admin/FaaS")
	FaaSAdminURL string

	// FileManagerURL is the URL for the file manager (optional)
	FileManagerURL string

	// AuthUserID returns the authenticated user ID from the request.
	// If it returns "", the user is treated as unauthenticated.
	AuthUserID func(r *http.Request) string
}

AdminOptions contains all dependencies and configuration for the FaaS admin.

Store and Logger are required. FuncLayout is optional — if nil, a default bare-bones HTML page is used (Bootstrap + Vue CDN).

Jump to

Keyboard shortcuts

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