confl icon indicating copy to clipboard operation
confl copied to clipboard

the style of nginx's configuration, how to deal it?

Open lemonl2 opened this issue 7 years ago • 3 comments

location ~* .(otf|eot|woff|ttf|woff2)$ { types {font/opentype otf;} types {application/vnd.ms-fontobject eot;} types {font/truetype ttf;} types {application/font-woff woff;} types {font/woff2 woff2;} }

location / { try_files $uri $uri/ /index.html =404; expires off; add_header Cache-Control "no-cache, no-store, must-revalidate"; add_header Strict-Transport-Security "max-age=86400" always; }

Just like nginx's configuration, how do i deal it ?

lemonl2 avatar Jun 01 '18 08:06 lemonl2

Its definitely not 100% nginx config but only inspired by.

This would be closest i can think of:

package main

import (
	"fmt"
	"log"

	"github.com/lytics/confl"
)

type Location struct {
	Location  string   `confl:"location"`
	TryFiles  string   `confl:"try_files"`
	Expires   string   `confl:"expires"`
	AddHeader []string `confl:"add_header"`
	Types     []string `confl:"types"`
}

type Locations struct {
	Location []Location
}

func main() {
	var rawData = `
    location [
        {
            location   : "~* .(otf|eot|woff|ttf|woff2)$"
            types : [ 
                 "{font/opentype otf;}" ,
                 "types {application/vnd.ms-fontobject eot;}" ,
           ]
        }
        {
            location  "/"
            try_files  "$uri $uri/ /index.html =404"
            expires off
            add_header : [
                'Cache-Control "no-cache, no-store, must-revalidate"',
                'Strict-Transport-Security "max-age=86400" always',
            ]
        }
    ]
	`

	var locs Locations
	if _, err := confl.Decode(rawData, &locs); err != nil {
		log.Fatal(err)
	}

	for _, l := range locs.Location {
		fmt.Printf("%+v\n", l)
	}
}

araddon avatar Jun 02 '18 01:06 araddon

@araddon Thanks! maybe it can't deal more complex configuration just like nginx.conf, I should seek another program to deal it!

lemonl2 avatar Jun 06 '18 06:06 lemonl2

@araddon Thanks! maybe it can't deal more complex configuration just like nginx.conf, I should seek another program to deal it!

have you found a better one?

mingmingshiliyu avatar Sep 04 '23 09:09 mingmingshiliyu