Open lemonl2 opened 6 years ago
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 Thanks! maybe it can't deal more complex configuration just like nginx.conf, I should seek another program to deal it!
@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?
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 ?