mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-15 19:22:46 -06:00
158a90b25b
* Grafana provider * grafana_data_source resource. Allows data sources to be created in Grafana. Supports all data source types that are accepted in the current version of Grafana, and will support any future ones that fit into the existing structure. * Vendoring of apparentlymart/go-grafana-api This is in anticipation of adding a Grafana provider plugin. * grafana_dashboard resource * Website documentation for the Grafana provider.
72 lines
1.4 KiB
Go
72 lines
1.4 KiB
Go
// +build none
|
|
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"compress/zlib"
|
|
"encoding/binary"
|
|
"fmt"
|
|
"go/format"
|
|
"io/ioutil"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
data, err := ioutil.ReadFile("table.txt")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
var buf bytes.Buffer
|
|
for _, line := range strings.Split(string(data), "\n") {
|
|
if strings.HasPrefix(line, "/*") || line == "" {
|
|
continue
|
|
}
|
|
sep := strings.IndexByte(line, ':')
|
|
if sep == -1 {
|
|
panic(line)
|
|
}
|
|
val, err := strconv.ParseInt(line[:sep], 0, 32)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
s, err := strconv.Unquote(line[sep+2:])
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if s == "" {
|
|
continue
|
|
}
|
|
if err := binary.Write(&buf, binary.LittleEndian, uint16(val)); err != nil {
|
|
panic(err)
|
|
}
|
|
if err := binary.Write(&buf, binary.LittleEndian, uint8(len(s))); err != nil {
|
|
panic(err)
|
|
}
|
|
buf.WriteString(s)
|
|
}
|
|
var cbuf bytes.Buffer
|
|
w, err := zlib.NewWriterLevel(&cbuf, zlib.BestCompression)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if _, err := w.Write(buf.Bytes()); err != nil {
|
|
panic(err)
|
|
}
|
|
if err := w.Close(); err != nil {
|
|
panic(err)
|
|
}
|
|
buf.Reset()
|
|
buf.WriteString("package unidecode\n")
|
|
buf.WriteString("// AUTOGENERATED - DO NOT EDIT!\n\n")
|
|
fmt.Fprintf(&buf, "var tableData = %q;\n", cbuf.String())
|
|
dst, err := format.Source(buf.Bytes())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if err := ioutil.WriteFile("table.go", dst, 0644); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|