Skip to content

Commit

Permalink
fix: remove awk stuff, use debug/buildinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
goproslowyo committed May 29, 2023
1 parent cd38069 commit 4b7ffa4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/StreamStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ var OPTIONAL_TAGS = []string{
// StreamersRepo struct represents fields to hold various data while updating status.
type StreamersRepo struct {
auth *httpauth.BasicAuth
awkPath string
inactiveFilePath string
inactiveMdText string
indexFilePath string
Expand Down
15 changes: 5 additions & 10 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"net/http"
"os"
"runtime/debug"
"strings"
"sync"

Expand All @@ -13,24 +14,20 @@ import (
log "github.com/sirupsen/logrus"
)

var version string = "unknown"

// main do the work.
func main() {
version, _ := debug.ReadBuildInfo()
log.Printf("started streamstatus\n%s\n", version.String())

// Setup file and repo paths.
var repoUrl string
if len(os.Getenv("SS_GH_REPO")) == 0 {
log.Warn("warning: no SS_GH_REPO specified in environment, defaulting to: https://github.com/infosecstreams/infosecstreams.github.io")
log.Info("no SS_GH_REPO specified in environment, defaulting to: https://github.com/infosecstreams/infosecstreams.github.io")
repoUrl = "https://github.com/infosecstreams/infosecstreams.github.io"
}
repoPath := strings.Split(repoUrl, "/")[4]
filePath := repoPath + "/index.md"
iFilePath := repoPath + "/inactive.md"
var awkPath string
var found bool
if awkPath, found = os.LookupEnv("SS_AWK_PATH"); !found {
awkPath = "/gawk"
}

// Setup auth.
if len(os.Getenv("SS_USERNAME")) == 0 || len(os.Getenv("SS_TOKEN")) == 0 || len(os.Getenv("SS_SECRETKEY")) == 0 {
Expand Down Expand Up @@ -75,7 +72,6 @@ func main() {
// Create StreamersRepo object
var repo = StreamersRepo{
auth: auth,
awkPath: awkPath,
inactiveFilePath: iFilePath,
indexFilePath: filePath,
repoPath: repoPath,
Expand All @@ -95,7 +91,6 @@ func main() {
}

// Listen and serve.
log.Printf("streamstatus v%s\n", version)
log.Printf("server starting on %s\n", port)
http.HandleFunc("/webhook/callbacks", repo.eventsubStatus)
log.Fatal(http.ListenAndServe(port, nil))
Expand Down
10 changes: 8 additions & 2 deletions src/utils.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package main

import (
"log"
"strings"

log "github.com/sirupsen/logrus"
)

// contains checks if a given string item is present in a slice of strings arr.
// It returns true if the item is present, false otherwise.
func contains(arr []string, item string) bool {
for _, v := range arr {
if strings.EqualFold(v, item) {
Expand All @@ -14,13 +17,16 @@ func contains(arr []string, item string) bool {
return false
}

// containsTags checks if any of the tags in the given slice of strings are present in another slice of strings.
// It returns true if any of the tags are present, false otherwise.
// It also logs a message for each tag found in the slice of strings.
func containsTags(arr []string, tags []string) bool {
found := false
for _, v := range arr {
for _, tag := range tags {
if strings.EqualFold(strings.ToLower(v), strings.ToLower(tag)) {
found = true
log.Printf("stream tag %s found\n", tag)
log.Debugf("stream tag %s found\n", tag)
}
}
}
Expand Down

0 comments on commit 4b7ffa4

Please sign in to comment.