freeswitch container: fix config generator, add support for static xml configs
All checks were successful
/ build-freeswitch (push) Successful in 19m54s

This commit is contained in:
Finn 2024-11-03 23:41:38 -08:00
parent a86ed9b3c3
commit 33ebe1a0b2
2 changed files with 48 additions and 1 deletions

View file

@ -1,6 +1,6 @@
<configuration name="modules.conf" description="Modules">
<modules>
<load module="mod_console"/>
{{ $_, $module := range .Modules }}<load module="{{ $module }}" />{{ end }}
{{ range $_, $module := .Modules }}<load module="{{ $module }}" />{{ end }}
</modules>
</configuration>

View file

@ -2,9 +2,13 @@ package main
import (
"embed"
"errors"
"fmt"
"io"
"io/fs"
"net/url"
"os"
"path/filepath"
"text/template"
"github.com/kelseyhightower/envconfig"
@ -17,6 +21,7 @@ type Options struct {
LogLevel string `envconfig:"LOG_LEVEL" default:"info"`
Gateway Gateway `envconfig:"GATEWAY"`
Modules []string `envconfig:"MODULES" default:"mod_event_socket,mod_sofia,mod_db,mod_dialplan_xml,mod_g723_1,mod_g729,mod_amr,mod_b64,mod_opus,mod_av,mod_sndfile,mod_native_file,mod_png,mod_local_stream,mod_tone_stream,mod_lua,mod_say_en"`
StaticXMLDir string `envconfig:"STATIC_XML_DIR" default:"/config"`
}
type Gateway struct {
@ -141,6 +146,48 @@ func main() {
}
fmt.Println("</section>")
staticConfigDirectories, err := os.ReadDir(options.StaticXMLDir)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return
}
panic(err)
}
for _, entry := range staticConfigDirectories {
if !entry.IsDir() {
continue
}
fmt.Printf("<section name=\"%s\">\n", entry.Name())
filepath.WalkDir(filepath.Join(options.StaticXMLDir, entry.Name()), func(path string, d fs.DirEntry, err error) error {
if d.IsDir() {
return nil
}
fmt.Printf("<!-- %s -->\n", path)
if err != nil {
fmt.Printf("<!-- ERROR: %v -->", err)
return err
}
f, err := os.Open(path)
if err != nil {
panic(err)
}
defer f.Close()
data, err := io.ReadAll(f)
if err != nil {
panic(err)
}
fmt.Println(string(data))
return nil
})
fmt.Println("</section>")
}
}
func (g *Gateway) Decode(value string) error {