[PR #4311] [CLOSED] feat: use sprig (slimmed down) for template function map #4961

Closed
opened 2026-05-05 14:52:04 -06:00 by gitea-mirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/fatedier/frp/pull/4311
Author: @debdutdeb
Created: 6/30/2024
Status: Closed

Base: devHead: extend-default-template-functions


📝 Commits (1)

  • 7664abb use sprig (slimmed down) for template function map

📊 Changes

3 files changed (+14 additions, -3 deletions)

View changed files

📝 go.mod (+1 -0)
📝 go.sum (+2 -0)
📝 pkg/config/load.go (+11 -3)

📄 Description

WHY

Gives more control over to how we can set our configs.

For example since not everything has an flag cmdline, one could simplify the interface through environment variables instead of editing the config file, manually or automatically.

e.g.

{{ $hosts := splitList "," .Envs.HOSTS }}
{{ range $index, $port := splitList "," .Envs.PORTS }}
[[proxies]]
name = {{ printf "web%d" $index | trim | quote }}
type = "http"
localPort = {{ $port }}
customDomains = [ {{ printf "%s.tunnel.example.com" (index $hosts $index) | trim | quote }} ]
{{ end }}

So I can have an function to simplify the interface like

# use like `frpc 8080 echoserver` should make localhost:8080 accessible at echoserver.tunnel.example.com
frpc() {
	local \
		port="$1" \
		name="$2"

	export HOSTS="$name"
	export PORTS="$port"

	command frpc -c ~/.config/frpc/config.toml
}

Note

Using slim-sprig because of

with all functions that depend on external (non standard library) or crypto packages removed

As noted in https://github.com/go-task/slim-sprig

Long term seems like there is an attempt at forking and maintaining separate version - https://github.com/go-sprout/sprout

I can change to sprout as is, but decided to start off with a lightweight version instead. Since still pre major 1, there's still the freedom to experiment.

Let me know whichever you prefer :)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/fatedier/frp/pull/4311 **Author:** [@debdutdeb](https://github.com/debdutdeb) **Created:** 6/30/2024 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `extend-default-template-functions` --- ### 📝 Commits (1) - [`7664abb`](https://github.com/fatedier/frp/commit/7664abb6d2505c21723fe91aa7b68c3c70d99eec) use sprig (slimmed down) for template function map ### 📊 Changes **3 files changed** (+14 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `go.mod` (+1 -0) 📝 `go.sum` (+2 -0) 📝 `pkg/config/load.go` (+11 -3) </details> ### 📄 Description ### WHY Gives more control over to how we can set our configs. For example since not everything has an flag cmdline, one could simplify the interface through environment variables instead of editing the config file, manually or automatically. e.g. ```toml {{ $hosts := splitList "," .Envs.HOSTS }} {{ range $index, $port := splitList "," .Envs.PORTS }} [[proxies]] name = {{ printf "web%d" $index | trim | quote }} type = "http" localPort = {{ $port }} customDomains = [ {{ printf "%s.tunnel.example.com" (index $hosts $index) | trim | quote }} ] {{ end }} ``` So I can have an function to simplify the interface like ```sh # use like `frpc 8080 echoserver` should make localhost:8080 accessible at echoserver.tunnel.example.com frpc() { local \ port="$1" \ name="$2" export HOSTS="$name" export PORTS="$port" command frpc -c ~/.config/frpc/config.toml } ``` ### Note Using `slim-sprig` because of > with all functions that depend on external (non standard library) or crypto packages removed As noted in https://github.com/go-task/slim-sprig Long term seems like there is an attempt at forking and maintaining separate version - https://github.com/go-sprout/sprout I can change to sprout as is, but decided to start off with a lightweight version instead. Since still pre major 1, there's still the freedom to experiment. Let me know whichever you prefer :) <!-- author to complete --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
gitea-mirror 2026-05-05 14:52:04 -06:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#4961
No description provided.