Skip to content

Commit

Permalink
Merge pull request #10 from jtsunne/5-allow-protocol-less-address-for…
Browse files Browse the repository at this point in the history
…-the-cluster-argument

add schema less (default is http)
  • Loading branch information
jtsunne authored Oct 24, 2022
2 parents a899dee + 61bdc1c commit 9f2c3e3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
26 changes: 26 additions & 0 deletions Utils/Common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package Utils

import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"os"
"time"
)

Expand All @@ -19,3 +22,26 @@ func GetJson(url string, target interface{}) error {

return json.NewDecoder(r.Body).Decode(target)
}

func ParseEsUrl(u string) string {
schema := "http"
port := "9200"
domain := ""
s, err := url.Parse(u)
if s.Host == "" {
s, err = url.Parse("//" + u)
}
if err != nil {
fmt.Println("Can't parse ESURL. Exiting...")
os.Exit(1)
}
if s.Scheme == "https" {
fmt.Println("GoLastic can't work with https yet. Exiting...")
os.Exit(1)
}
if s.Port() != "" {
port = s.Port()
}
domain = s.Host
return fmt.Sprintf("%s://%s:%s", schema, domain, port)
}
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func init() {
fmt.Println("Elasticsearch cluster have to be set. Exiting...")
os.Exit(0)
}
EsUrl = os.Args[1]
EsUrl = Utils.ParseEsUrl(os.Args[1])
} else {
EsUrl = os.Getenv("ESURL")
EsUrl = Utils.ParseEsUrl(os.Getenv("ESURL"))
}
fmt.Println("ES_URL=" + EsUrl)

Expand Down Expand Up @@ -88,6 +88,7 @@ Indices Page HotKeys:
Ctrl+\ - Set filter for the Indices view
Ctrl+E - Remove selected Index
Ctrl+P - Set Replicas Count for the selected index
Enter - Show Index Settings
`)

pages.AddPage("info",
Expand Down

0 comments on commit 9f2c3e3

Please sign in to comment.