Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nginxinc/nginx-go-crossplane
A library for working with NGINX configs in Go
https://github.com/nginxinc/nginx-go-crossplane
configuration configuration-files configuration-management go golang nginx nginx-configuration nginx-server
Last synced: about 16 hours ago
JSON representation
A library for working with NGINX configs in Go
- Host: GitHub
- URL: https://github.com/nginxinc/nginx-go-crossplane
- Owner: nginxinc
- License: apache-2.0
- Created: 2019-01-29T09:49:55.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-12-09T17:53:38.000Z (23 days ago)
- Last Synced: 2024-12-24T12:24:27.539Z (8 days ago)
- Topics: configuration, configuration-files, configuration-management, go, golang, nginx, nginx-configuration, nginx-server
- Language: Go
- Homepage:
- Size: 1.1 MB
- Stars: 59
- Watchers: 29
- Forks: 15
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
- Security: SECURITY.md
- Support: SUPPORT.md
Awesome Lists containing this project
README
# nginx-go-crossplane
A Go port of the NGINX config/JSON converter [crossplane](https://github.com/nginxinc/crossplane).## Parse
This is an example that takes a path to an NGINX config file, converts it to JSON, and prints the result to stdout.
```go
package mainimport (
"encoding/json"
"fmt"
"os""github.com/nginxinc/nginx-go-crossplane"
)func main() {
path := os.Args[1]payload, err := crossplane.Parse(path, &crossplane.ParseOptions{})
if err != nil {
panic(err)
}b, err := json.Marshal(payload)
if err != nil {
panic(err)
}fmt.Println(string(b))
}
```## Build
This is an example that takes a path to a JSON file, converts it to an NGINX config, and prints the result to stdout.
```go
package mainimport (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os""github.com/nginxinc/nginx-go-crossplane"
)func main() {
path := os.Args[1]file, err := os.Open(path)
if err != nil {
panic(err)
}content, err := ioutil.ReadAll(file)
if err != nil {
panic(err)
}var payload crossplane.Payload
if err = json.Unmarshal(content, &payload); err != nil {
panic(err)
}var buf bytes.Buffer
if err = crossplane.Build(&buf, payload.Config[0], &crossplane.BuildOptions{}); err != nil {
panic(err)
}fmt.Println(buf.String())
}
```# Generate support for third-party modules
This is a simple example that takes the path of a third-party module source code to generate support for it. For detailed usage of the tool, please run
`go run ./cmd/generate/ --help`.
Assuming the source code path of that module is `./src`, you can call `go run ./cmd/generate/ --src-path=./src -directive-map-name=directives -match-func-name=Match -match-func-comment=comment`. The output will be similar to:```go
/**
* Copyright (c) F5, Inc.
*
* This source code is licensed under the Apache License, Version 2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/// Code generated by generator; DO NOT EDIT.
// All the definitions are extracted from the source code
// Each bit mask describes these behaviors:
// - how many arguments the directive can take
// - whether or not it is a block directive
// - whether this is a flag (takes one argument that's either "on" or "off")
// - which contexts it's allowed to be inpackage crossplane
var directives = map[string][]uint{
"my_directive_1": {
bitmask01|bitmask02|...,
bitmask11|bitmask12|...,
...
},
"my_directive_2": {
bitmask01|bitmask02|...,
bitmask11|bitmask12|...,
...
},
}// comment
func Match(directive string) ([]uint, bool) {
m, ok := directives[directive]
return m, ok
}
```
You can redirect the stdout into a `.go` file, and pass the generated `matchFunc` to `ParseOptions.DirectiveSources` when invoking `Parse`.## Contributing
If you'd like to contribute to the project, please read our [Contributing guide](CONTRIBUTING.md).
## License
[Apache License, Version 2.0](https://github.com/nginxinc/nginx-go-crossplane/blob/main/LICENSE)
© [F5 Networks, Inc.](https://www.f5.com/) 2022