|
1 | 1 | #  |
2 | 2 |
|
3 | | -## HAProxy configuration parser |
| 3 | +<br/> |
4 | 4 |
|
5 | | -[](https://github.com/haproxy/haproxy/blob/master/CONTRIBUTING) |
6 | | -[](LICENSE) |
| 5 | +:warning: This project has been merged with [client-native](https://github.com/haproxytech/client-native) project. |
7 | 6 |
|
8 | | -### autogenerated code |
9 | | -if you change types/types.go you need to run |
10 | | -```bash |
11 | | -make generate |
| 7 | +use |
| 8 | +```go |
| 9 | +import "github.com/haproxytech/client-native/v6/config-parser" |
12 | 10 | ``` |
13 | | -### Contributing |
14 | | - |
15 | | -For commit messages and general style please follow the haproxy project's [CONTRIBUTING guide](https://github.com/haproxy/haproxy/blob/master/CONTRIBUTING) and use that where applicable. |
16 | 11 |
|
17 | | -Please use `golangci-lint run` from [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) for linting code. |
18 | | - |
19 | | -### Example |
| 12 | +instead of |
20 | 13 |
|
21 | 14 | ```go |
22 | | -package main |
23 | | - |
24 | | -import ( |
25 | | - "github.com/haproxytech/config-parser/v5" |
26 | | - "github.com/haproxytech/config-parser/v5/options" |
27 | | - "github.com/haproxytech/config-parser/v5/parsers/http/actions" |
28 | | - // ... |
29 | | -) |
30 | | -// ... |
31 | | - |
32 | | -func main() { |
33 | | - p, err := parser.New(options.Path("config.cfg")) |
34 | | - /* p, err := parser.New( |
35 | | - options.UseMd5Hash, |
36 | | - options.Path("config.cfg") |
37 | | - )*/ |
38 | | - if err != nil { |
39 | | - log.Panic(err) |
40 | | - } |
41 | | - |
42 | | - { |
43 | | - data, _ := p.Get(parser.Comments, parser.CommentsSectionName, "# _version", true) |
44 | | - if err == errors.ErrFetch { |
45 | | - log.Panicln("we have an fetch error !!") |
46 | | - } |
47 | | - ver, _ := data.(*types.Int64C) |
48 | | - ver.Value = ver.Value + 1 |
49 | | - } |
50 | | - |
51 | | - { |
52 | | - p.Set(parser.Frontends, "http", "option forwardfor", types.OptionForwardFor{}) |
53 | | - } |
54 | | - |
55 | | - { |
56 | | - // for options that can exists multiple times in config Insert is preffered |
57 | | - // |
58 | | - // setting http-request & http-response is a bit different |
59 | | - // since they accept multiple structs |
60 | | - httpRequestActionDeny := &actions.Deny{ |
61 | | - DenyStatus: "0", |
62 | | - Cond: "unless", |
63 | | - CondTest: "{ src 127.0.0.1 }", |
64 | | - } |
65 | | - err = p.Insert(parser.Backends, "web_servers", "http-request", httpRequestActionDeny) |
66 | | - // you can also choose index where action should be inserted |
67 | | - err = p.Insert(parser.Backends, "web_servers", "http-request", httpRequestActionDeny, 2) |
68 | | - } |
69 | | - |
70 | | - { |
71 | | - data, err := p.Get(parser.Global, parser.GlobalSectionName, "stats socket") |
72 | | - if err != nil { |
73 | | - log.Panicln(err) |
74 | | - } |
75 | | - val, _ := data.([]types.Socket) |
76 | | - log.Println(val[0]) |
77 | | - val[0].Path = "$PWD/haproxy-runtime-api.1.sock" |
78 | | - log.Println(val[0]) |
79 | | - } |
80 | | - |
81 | | - { |
82 | | - data, err := p.Get(parser.Global, parser.GlobalSectionName, "daemon") |
83 | | - log.Println(data, err) |
84 | | - if err == errors.ErrFetch { |
85 | | - log.Panicln("we have an fetch error !!") |
86 | | - } |
87 | | - //remove it |
88 | | - p.Set(parser.Global, parser.GlobalSectionName, "daemon", nil) |
89 | | - } |
90 | | - |
91 | | - { |
92 | | - datar, err := p.Get(parser.Resolvers, "ns1", "nameserver") |
93 | | - if err == nil { |
94 | | - ns := datar.([]types.Nameserver) |
95 | | - log.Println(ns[0].Name, ns[0].Address) |
96 | | - log.Println(ns[1].Name, ns[1].Address) |
97 | | - ns[1].Name = "hahaha" |
98 | | - ns[0].Address = "0.0.0.0:8080" |
99 | | - } |
100 | | - datar, err = p.Get(parser.Resolvers, "ns1", "nameserver") |
101 | | - if err == nil { |
102 | | - ns := datar.([]types.Nameserver) |
103 | | - log.Println(ns[0].Name, ns[0].Address) |
104 | | - log.Println(ns[1].Name, ns[1].Address) |
105 | | - } |
106 | | - } |
| 15 | +import "github.com/haproxytech/config-parser/v5" |
| 16 | +``` |
107 | 17 |
|
108 | | - { |
109 | | - log.Println("nbproc ==================================================") |
110 | | - data, err := p.Get(parser.Global, parser.GlobalSectionName, "nbproc") |
111 | | - if err != nil { |
112 | | - log.Println(err) |
113 | | - } else { |
114 | | - d := data.(*types.Int64C) |
115 | | - log.Println(d.Value) |
116 | | - d.Value = 5 |
117 | | - } |
118 | | - } |
| 18 | +## Maintenance mode |
119 | 19 |
|
120 | | - p.Save(configFilename) |
121 | | -} |
| 20 | +This library remains supported until September 2025 (bug fixes only). |
122 | 21 |
|
123 | | -``` |
| 22 | +All new development must be done on the [client-native](https://github.com/haproxytech/client-native) repository. |
124 | 23 |
|
125 | 24 | ## License |
126 | 25 |
|
|
0 commit comments