Skip to content

Go plugin guide

Ryan Wynn edited this page Jun 19, 2025 · 6 revisions

This page shows how you can build and run a custom monstache docker container image with an embedded go plugin.

Given a folder with contents...

Dockerfile  plugin.go

plugin.go as...

package main
import (
	"github.com/rwynn/monstache/v6/monstachemap"
	"strings"
)
// a plugin to convert document values to uppercase
func Map(input *monstachemap.MapperPluginInput) (output *monstachemap.MapperPluginOutput, err error) {
	doc := input.Document
	for k, v := range doc {
		switch v.(type) {
		case string:
			doc[k] = strings.ToUpper(v.(string))
		}
	}
	output = &monstachemap.MapperPluginOutput{Document: doc}
	return
}

Dockerfile as...

FROM golang:1.24.4-alpine3.21 AS build
WORKDIR /src
RUN --mount=target=. \
    --mount=type=cache,target=/root/.cache/go-build \
    --mount=type=cache,target=/go/pkg \
	go mod download; \
    go build -buildmode=plugin -o out/plugin.so plugin.go

FROM rwynn/monstache:6.7.22
COPY --from=build out/plugin.so /bin

Generate a go.mod

go mod init github.com/rwynn/monstache/v6

Build the image...

docker build -t monstache .

Run the container with the plugin...

docker run --rm --net=host monstache:latest -mapper-plugin-path /bin/plugin.so

Clone this wiki locally

⌂ 换网址