Skip to content

Commit

Permalink
Let there be env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
chmouel committed Mar 31, 2023
1 parent 2ab7aec commit 00ce7b2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
9 changes: 8 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ nfpms:
maintainer: Chmouel Boudjnah <[email protected]>
license: Apache 2.0
formats:
- apk
- deb
- rpm
bindir: /usr/bin
Expand All @@ -73,7 +74,13 @@ nfpms:
darwin: macOS
linux: Linux
windows: Windows

contents:
- src: ./misc/gosmee-server.service
dst: /etc/systemd/system/gosmee-server.service
type: "config|noreplace"
- src: ./misc/gosmee.service
dst: /etc/systemd/system/gosmee-client.service
type: "config|noreplace"
changelog:
sort: asc
use: github
Expand Down
22 changes: 16 additions & 6 deletions gosmee/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gosmee

import (
"fmt"
"net/url"
"os"
"strings"

Expand Down Expand Up @@ -81,13 +82,22 @@ accessible endpoint and forward request to your local service`,
UsageText: "gosmee [command options] SMEE_URL LOCAL_SERVICE_URL",
Usage: "Make a client from the relay server to your local service",
Action: func(c *cli.Context) error {
if c.NArg() != 2 {
return fmt.Errorf("need at least a serverURL and a targetURL as arguments, ie: gosmee client https://smee.io/aBcDeF http://localhost:8080")
var smeeURL, targetURL string
if os.Getenv("GOSMEE_URL") != "" && os.Getenv("GOSMEE_TARGET_URL") != "" {
smeeURL = os.Getenv("GOSMEE_URL")
targetURL = os.Getenv("GOSMEE_TARGET_URL")
} else {
if c.NArg() != 2 {
return fmt.Errorf("need at least a smeeURL and a targetURL as arguments, ie: gosmee client https://server.smee.url/aBcdeFghijklmn http://localhost:8080")
}
smeeURL = c.Args().Get(0)
targetURL = c.Args().Get(1)
}
smeeURL := c.Args().Get(0)
targetURL := c.Args().Get(1)
if !strings.HasPrefix(targetURL, "http") {
return fmt.Errorf("targetURL should start with http(s)")
if _, err := url.Parse(smeeURL); err != nil {
return fmt.Errorf("smeeURL %s is not a valid url %w", smeeURL, err)
}
if _, err := url.Parse(targetURL); err != nil {
return fmt.Errorf("target url %s is not a valid url %w", targetURL, err)
}
decorate := true
if !isatty.IsTerminal(os.Stdout.Fd()) {
Expand Down
10 changes: 10 additions & 0 deletions misc/gosmee-server.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Gosmee Server

[Service]
ExecStart=gosmee server
User=gosmee
EnvironmentFile=/etc/gosmee.env

[Install]
WantedBy=default.target
1 change: 1 addition & 0 deletions misc/gosmee.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Description=Gosmee Forward

[Service]
ExecStart=gosmee client https://smee.io/abcdef http://localhost:8080
EnvironmentFile=/etc/gosmee.env

[Install]
WantedBy=default.target

0 comments on commit 00ce7b2

Please sign in to comment.