dotenv configure added.

This commit is contained in:
dalbodeule
2025-10-14 05:38:07 +09:00
parent 01677d8865
commit 301113a560
5 changed files with 18 additions and 2 deletions

4
.gitignore vendored
View File

@@ -240,4 +240,6 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk
# End of https://www.toptal.com/developers/gitignore/api/go,goland,git,dotenv,database,macos,linux,windows
# End of https://www.toptal.com/developers/gitignore/api/go,goland,git,dotenv,database,macos,linux,windows
keys/

1
go.mod
View File

@@ -6,6 +6,7 @@ require github.com/gliderlabs/ssh v0.3.8
require (
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/joho/godotenv v1.5.1 // indirect
golang.org/x/crypto v0.43.0 // indirect
golang.org/x/sys v0.37.0 // indirect
)

2
go.sum
View File

@@ -2,6 +2,8 @@ github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFI
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=
github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=

1
inc.env Normal file
View File

@@ -0,0 +1 @@
PORT=2222

12
main.go
View File

@@ -3,13 +3,22 @@ package main
import (
"io"
"log"
"os"
"sshchat/utils"
"github.com/gliderlabs/ssh"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
port := os.Getenv("PORT")
keys, err := utils.CheckHostKey()
if err != nil {
log.Print("Failed to check SSH keys: generate one.\n", err)
@@ -29,12 +38,13 @@ func main() {
}
s := &ssh.Server{
Addr: ":2222",
Addr: ":" + port,
Handler: sessionHandler,
}
for _, key := range keys {
s.AddHostKey(key)
}
log.Print("Listening on :" + port)
log.Fatal(s.ListenAndServe())
}