Ben 1 year ago
parent
commit
cf97493a30
9 changed files with 24 additions and 27 deletions
  1. 4 0
      .gitignore
  2. 0 8
      .idea/.gitignore
  3. 5 4
      cmd/master.go
  4. 1 1
      cmd/slave.go
  5. 1 1
      go.mod
  6. 8 8
      internal/server/server.go
  7. 0 4
      proxy.iml
  8. 1 1
      run_master.sh
  9. 4 0
      run_slave.sh

+ 4 - 0
.gitignore

@@ -0,0 +1,4 @@
+.idea
+*.iml
+master
+slave

+ 0 - 8
.idea/.gitignore

@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml

+ 5 - 4
cmd/master/master.go → cmd/master.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"be-vpn/internal/server"
 	"github.com/gin-gonic/gin"
 	"log"
 )
@@ -8,10 +9,10 @@ import (
 func main() {
 	r := gin.Default()
 	r.Use(gin.Recovery())
-	r.POST("/register", register)
-	r.GET("/list", list)
-	r.GET("/detail", detail)
-	r.GET("/health", health)
+	r.POST("/register", server.Register)
+	r.GET("/list", server.List)
+	r.GET("/detail", server.Detail)
+	r.GET("/health", server.Health)
 
 	if err := r.Run(":8080"); err != nil {
 		log.Fatalf("err: %+v", err)

+ 1 - 1
cmd/slave/slave.go → cmd/slave.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"be-vpn/internal/dto"
 	"bytes"
 	"encoding/json"
 	"github.com/robfig/cron/v3"
@@ -9,7 +10,6 @@ import (
 	"log"
 	"net/http"
 	"os"
-	"proxy/internal/dto"
 )
 
 func main() {

+ 1 - 1
go.mod

@@ -1,4 +1,4 @@
-module proxy
+module be-vpn
 
 go 1.19
 

+ 8 - 8
cmd/master/server.go → internal/server/server.go

@@ -1,12 +1,12 @@
-package main
+package server
 
 import (
+	"be-vpn/internal/dto"
+	"be-vpn/internal/model"
+	"be-vpn/internal/util"
 	"github.com/gin-gonic/gin"
 	"log"
 	"net/http"
-	"proxy/internal/dto"
-	"proxy/internal/model"
-	"proxy/internal/util"
 	"sync"
 	"time"
 )
@@ -14,7 +14,7 @@ import (
 var nodes = make([]*model.Node, 0)
 var locker = sync.RWMutex{}
 
-func register(c *gin.Context) {
+func Register(c *gin.Context) {
 	locker.Lock()
 	defer locker.Unlock()
 
@@ -50,7 +50,7 @@ func register(c *gin.Context) {
 	log.Printf("update nodes: %+v", nodes)
 }
 
-func list(c *gin.Context) {
+func List(c *gin.Context) {
 	locker.RLock()
 	defer locker.RUnlock()
 
@@ -82,7 +82,7 @@ func list(c *gin.Context) {
 	})
 }
 
-func detail(c *gin.Context) {
+func Detail(c *gin.Context) {
 	locker.RLock()
 	defer locker.RUnlock()
 
@@ -108,6 +108,6 @@ func detail(c *gin.Context) {
 	})
 }
 
-func health(c *gin.Context) {
+func Health(c *gin.Context) {
 	c.JSON(http.StatusOK, gin.H{"status": "up"})
 }

+ 0 - 4
proxy.iml

@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module version="4">
-  <component name="Go" enabled="true" />
-</module>

+ 1 - 1
run_master.sh

@@ -1,4 +1,4 @@
 git pull origin master
-go build ./cmd/master/master.go
+go build ./cmd/master.go
 lsof -i:8080 | awk '{print "kill -9 " $2}' | sudo sh -x
 nohup ./master &

+ 4 - 0
run_slave.sh

@@ -0,0 +1,4 @@
+git pull origin master
+go build ./cmd/slave.go
+ps aux | grep slave | awk '{print "kill -9 " $2}' | sudo sh -x
+nohup ./slave &