Example of Go embed in v2

I would like to see another equivalence of this in V2

package main

import (

	_ "github.com/mholt/caddy/caddyhttp"

func init() {
	// configure default caddyfile
	caddy.SetDefaultCaddyfileLoader("default", caddy.LoaderFunc(defaultLoader))

func main() {
	caddy.AppName = "Sprocketplus"
	caddy.AppVersion = "1.2.3"

	// load caddyfile
	caddyfile, err := caddy.LoadCaddyfile("http")
	if err != nil {

	// start caddy server
	instance, err := caddy.Start(caddyfile)
	if err != nil {


// provide loader function
func defaultLoader(serverType string) (caddy.Input, error) {
	contents, err := ioutil.ReadFile(caddy.DefaultConfigFile)
	if err != nil {
		if os.IsNotExist(err) {
			return nil, nil
		return nil, err
	return caddy.CaddyfileInput{
		Contents:       contents,
		Filepath:       caddy.DefaultConfigFile,
		ServerTypeName: serverType,
	}, nil

Welcome to the forum, Edwin!

While you certainly can embed Caddy 2 in another Go application (without much difficulty, I suppose I could find some time to write up a little guide like we have for Caddy 1?), we’ve designed Caddy 2 primarily so that your Go app is embedded into Caddy 2. In other words, the other way around.

What are you trying to accomplish, exactly?

Good to hear.
I already have a few go servers up and running.
My hope is to add graceful restart functionality, autoTLS, and a way to easily reverse proxy (in native Go).
V1 will definitely work, but it looks like everything is moving to V2 now.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.