keksvpn/cmd/sample-server/main.go

37 lines
647 B
Go
Raw Normal View History

2022-02-27 03:22:11 +00:00
package main
import (
"fmt"
"keksvpn/pkg/wgfunc"
"time"
)
func main() {
2022-02-27 04:08:06 +00:00
serverConfig := wgfunc.WireGuardConfig{
2022-02-27 03:22:11 +00:00
Name: "sample-server",
IPRanges: []string{"10.0.1.0/24"},
Port: 0,
2022-02-27 04:08:06 +00:00
PrivateKey: "kDUIomFdDOW0VaOMS6Vu8+1rw/8SemeobSa7ZN66J38=",
2022-02-27 03:22:11 +00:00
}
2022-02-27 04:08:06 +00:00
server, err := wgfunc.NewWireGuard(serverConfig)
2022-02-27 03:22:11 +00:00
if err != nil {
panic(err)
}
2022-02-27 04:08:06 +00:00
fmt.Println("Start WireGuard")
2022-02-27 03:22:11 +00:00
err = server.Up()
if err != nil {
server.Down()
panic(err)
}
2022-02-27 04:08:06 +00:00
defer server.Down()
2022-02-27 03:22:11 +00:00
2022-02-27 04:08:06 +00:00
fmt.Println("WireGuard online")
2022-02-27 03:22:11 +00:00
time.Sleep(5 * time.Second)
fmt.Println("Shoutdown server")
err = server.Down()
if err != nil {
panic(err)
2022-02-27 04:08:06 +00:00
}
2022-02-27 03:22:11 +00:00
fmt.Println("bye")
}