github.com/krum110487/go-htaccess@v0.0.0-20240316004156-60641c8e7598/example/parseExample/main.go (about) 1 //nolint:gosec 2 package main 3 4 import ( 5 "encoding/json" 6 "fmt" 7 8 "github.com/krum110487/go-htaccess/parser" 9 ) 10 11 func main() { 12 //Parse to AST 13 //Make a second p 14 v, err := parser.Parse( 15 ` 16 RewriteCond %{HTTP_USER_AGENT} "=This Robot/1.0" 17 RewriteRule test2 18 19 RewriteCond /var/www/%{REQUEST_URI} !-f 20 RewriteRule ^(.+) /other/archive/$1 [R] 21 22 RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'" 23 RewriteRule "^/images" "-" [F] 24 25 RewriteCond "%{REMOTE_HOST}" "^host1" [OR] 26 RewriteCond "%{REMOTE_HOST}" "^host2" [OR,E=VAR:VALUE] 27 RewriteCond "%{REMOTE_HOST}" "^host3" 28 RewriteRule test 29 `) 30 31 //RewriteCond pushes to rewritecond set 32 //expr pushes to expression set. 33 34 if err != nil { 35 panic(err) 36 } 37 38 //repr.Println(v, repr.Indent(" "), repr.OmitEmpty(true)) 39 40 d, err := json.MarshalIndent(v, " ", " ") 41 fmt.Println(string(d)) 42 //fmt.Printf("%d", v.Directives[len(v.Directives)-1].Entry.Paramaters[0].Number) 43 }