caddyhcl

package module
v0.0.0-...-f370841 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: MIT Imports: 9 Imported by: 0

README

caddy-hcl

Go

Caddy config adapter for HCL (HashiCorp Configuration Language)

A significant chunk of the code is borrowed from https://github.com/tmccombs/hcl2json, credit to them for figuring out the HCL to JSON conversion.

Install

Install with xcaddy.

xcaddy build \
    --with github.com/francislavoie/caddy-hcl

Or download from the Caddy website: https://caddyserver.com/download

Usage

Specify the --adapter flag to caddy run

caddy run --config /path/to/hcl/caddy.hcl --adapter hcl

Limitations

Note that currently, HCL block syntax is not properly supported, because of ambiguity in the HCL syntax which makes objects at the end of blocks get wrapped with an array. This meant that block syntax generates JSON that Caddy considers invalid, because for example, it expects objects as the value for each server. Ideally, if I had my way, the config would look more like this (but this doesn't work):

apps http servers srv0 {
    ...
}

Example

Here's an example of a simple proxy server.

apps = {
  http = {
    servers = {
      srv0 = {
        listen = [":443"]

        routes = [
          {
            match = [{ host = ["example.com"] }]
            handle = [{
              handler = "subroute"
              routes = [{
                handle = [{
                  handler = "reverse_proxy"
                  upstreams = [{ dial = "localhost:8000" }]
                }]
              }]
            }]

            terminal = true
          }
        ]
      }
    }
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func File

func File(file *hcl.File, options map[string]interface{}) ([]byte, error)

File takes an HCL file and converts it to its JSON representation.

Types

type HCLAdapter

type HCLAdapter struct{}

HCLAdapter adapts HCL to Caddy JSON.

func (HCLAdapter) Adapt

func (a HCLAdapter) Adapt(body []byte, options map[string]interface{}) ([]byte, []caddyconfig.Warning, error)

Adapt converts the HCL config to Caddy JSON.

Jump to

Keyboard shortcuts

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