-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
79 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package config | ||
|
||
import "os" | ||
|
||
var Platform platform | ||
|
||
type platform int | ||
|
||
const ( | ||
Heroku platform = iota | ||
Railway | ||
Okteto | ||
Local | ||
) | ||
|
||
func initPlatform() { | ||
switch { | ||
case checkEnv("DYNO"): | ||
Platform = Heroku | ||
case checkEnv("RAILWAY_STATIC_URL"): | ||
Platform = Railway | ||
case checkEnv("OKTETO_TOKEN"): | ||
Platform = Okteto | ||
default: | ||
Platform = Local | ||
} | ||
} | ||
|
||
func checkEnv(env string) bool { | ||
return os.Getenv(env) != "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
var tempDir = os.TempDir() | ||
|
||
func Restart(delay int, chatId int64, msgId int, msgText string) { | ||
// command := fmt.Sprintf("run main.go -delay=5 -chat=%d -msg=%d", chat.GetID(), u.EffectiveMessage.ID) | ||
args := []string{fmt.Sprintf("-delay=%d", delay), fmt.Sprintf("-chat=%d", chatId), fmt.Sprintf("-msg_id=%d", msgId), fmt.Sprintf("-msg_text=%s", msgText)} | ||
command := []string{"run", "main.go"} | ||
command = append(command, args...) | ||
// fmt.Println(command) | ||
executable, err := os.Executable() | ||
if strings.Contains(executable, tempDir) || err != nil { | ||
executable = "go" | ||
} | ||
cmd := exec.Command(executable, command...) | ||
cmd.Stderr = os.Stderr | ||
cmd.Stdout = os.Stdout | ||
cmd.Stdin = os.Stdin | ||
cmd.Start() | ||
cmd.Process.Release() | ||
os.Exit(1) | ||
} |