Skip to content

Commit

Permalink
add some config as env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
sjurtf committed Mar 14, 2021
1 parent 294f922 commit 00260ea
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#/bin/sh
docker build . -t xmltv-exporter
docker build . -t xmltv-exporter:development
8 changes: 6 additions & 2 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ import (
"xmltv-exporter/xmltv"
)

func ServeEpg() {
func ServeEpg(port string) {

http.HandleFunc("/channels-norway.xml", ChannelListHandler)
http.HandleFunc("/", ChannelHandler)

if err := http.ListenAndServe(":8080", nil); err != nil {
if port == "" {
port = "8080"
}

if err := http.ListenAndServe(":"+port, nil); err != nil {
log.Fatal(err)
}
}
Expand Down
11 changes: 9 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package main

import "xmltv-exporter/cmd"
import (
"os"
"xmltv-exporter/cmd"
"xmltv-exporter/xmltv"
)

func main() {
xmltv.Init(os.Getenv("XMLTV_DOMAIN"))

cmd.MapEgp()
cmd.ServeEpg()
cmd.ServeEpg(os.Getenv("XMLTV_PORT"))

}
27 changes: 17 additions & 10 deletions xmltv/xmltv.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@ import (
)

const (
XmltvDateFormat = "20060102150400 -0700"
XmltvEpisodeStd = "xmtv_ns"
GeneratorName = "xmltv.sjurtf.net"
GeneratorUrl = "https://xmltv.sjurtf.net/"
DocHeader = `<?xml version="1.0" encoding="utf-8"?><!DOCTYPE tv SYSTEM "xmltv.dtd">`
XmltvDateFormat = "20060102150400 -0700"
XmltvEpisodeStd = "xmtv_ns"
GeneratorName = "xmltv.sjurtf.net"
DocHeader = `<?xml version="1.0" encoding="utf-8"?><!DOCTYPE tv SYSTEM "xmltv.dtd">`
defaultGeneratorUrl = "https://xmltv.sjurtf.net/"
)

var channelCache []tv2.Channel
var channelGuideMap map[string]map[string][]tv2.Program
var generatorUrl string

func Init(url string) {
generatorUrl = defaultGeneratorUrl
if url != "" {
generatorUrl = url
}
}

func BuildCache(date time.Time, channel tv2.Channel) {
if channelGuideMap == nil {
Expand Down Expand Up @@ -51,10 +59,9 @@ func GetChannelList() ([]byte, error) {
var programs []Programme
for _, c := range channelCache {
channel := Channel{
Id: xmlChannelIdMap[c.Id],
Name: c.Name,
//BaseUrl: GeneratorUrl,
BaseUrl: "http://host.docker.internal:8080/",
Id: xmlChannelIdMap[c.Id],
Name: c.Name,
BaseUrl: generatorUrl,
}
channels = append(channels, channel)
}
Expand Down Expand Up @@ -97,7 +104,7 @@ func getProgramsForChannel(channelId string, date time.Time) []Programme {
func marshall(channels []Channel, programs []Programme) ([]byte, error) {
resp := Response{
GeneratorName: GeneratorName,
GeneratorUrl: GeneratorUrl,
GeneratorUrl: generatorUrl,
ChannelList: channels,
ProgrammeList: programs,
}
Expand Down

0 comments on commit 00260ea

Please sign in to comment.