Преглед изворни кода

Moved main server and client packages under cmds/ (#6)

insomniac пре 7 година
родитељ
комит
6d9a00f8a1
7 измењених фајлова са 46 додато и 32 уклоњено
  1. 5 4
      .gitignore
  2. 8 3
      README.md
  3. 0 0
      cmds/client/main.go
  4. 0 0
      cmds/coredhcp/config.yml.example
  5. 0 0
      cmds/coredhcp/leases.txt.example
  6. 32 0
      cmds/coredhcp/main.go
  7. 1 25
      server.go

+ 5 - 4
.gitignore

@@ -1,4 +1,5 @@
-leases.txt
-coredhcp
-client/client
-config.yml
+.*.swp
+cmds/coredhcp/leases.txt
+cmds/coredhcp/config.yml
+cmds/coredhcp/coredhcp
+cmds/client/client

+ 8 - 3
README.md

@@ -30,8 +30,12 @@ See also [config.yml.example](config.yml.example).
 
 ## Build and run
 
-Once you have a working configuration in `config.yml`, you can build and run the server:
+The server is located under [cmds/coredhcp/](cmds/coredhcp/), so enter that
+directory first.
+
+Once you have a working configuration in `config.yml` (see [config.yml.example](cmds/coredhcp/config.yml.example)), you can build and run the server:
 ```
+$ cd cmds/coredhcp
 $ go build
 $ sudo ./coredhcp
 2018/12/19 14:27:17 Registering plugin "file"
@@ -53,9 +57,10 @@ $ sudo ./coredhcp
 ...
 ```
 
-Then try it with the local test client:
+Then try it with the local test client, that is located under
+[cmds/client/](cmds/client):
 ```
-$ cd client
+$ cd cmds/client
 $ go build
 $ sudo ./client
 2018/12/19 14:29:05 &{ReadTimeout:3s WriteTimeout:3s LocalAddr:[::1]:546 RemoteAddr:[::1]:547}

+ 0 - 0
client/main.go → cmds/client/main.go


+ 0 - 0
config.yml.example → cmds/coredhcp/config.yml.example


+ 0 - 0
leases.txt.example → cmds/coredhcp/leases.txt.example


+ 32 - 0
cmds/coredhcp/main.go

@@ -0,0 +1,32 @@
+package main
+
+import (
+	"log"
+	"time"
+
+	"github.com/coredhcp/coredhcp"
+	"github.com/coredhcp/coredhcp/config"
+	_ "github.com/coredhcp/coredhcp/plugins/file"
+	_ "github.com/coredhcp/coredhcp/plugins/server_id"
+)
+
+// Application variables
+var (
+	AppName    = "CoreDHCP"
+	AppVersion = "v0.1"
+)
+
+func main() {
+	config, err := config.Parse()
+	if err != nil {
+		log.Fatal(err)
+	}
+	server := coredhcp.NewServer(config)
+	if err := server.Start(); err != nil {
+		log.Fatal(err)
+	}
+	if err := server.Wait(); err != nil {
+		log.Print(err)
+	}
+	time.Sleep(time.Second)
+}

+ 1 - 25
main.go → server.go

@@ -1,26 +1,17 @@
-package main
+package coredhcp
 
 import (
 	"errors"
 	"log"
 	"net"
-	"time"
 
 	"github.com/coredhcp/coredhcp/config"
 	"github.com/coredhcp/coredhcp/handler"
 	"github.com/coredhcp/coredhcp/plugins"
-	_ "github.com/coredhcp/coredhcp/plugins/file"
-	_ "github.com/coredhcp/coredhcp/plugins/server_id"
 	"github.com/insomniacslk/dhcp/dhcpv4"
 	"github.com/insomniacslk/dhcp/dhcpv6"
 )
 
-// Application variables
-var (
-	AppName    = "CoreDHCP"
-	AppVersion = "v0.1"
-)
-
 // Server is a CoreDHCP server structure that holds information about
 // DHCPv6 and DHCPv4 servers, and their respective handlers.
 type Server struct {
@@ -143,18 +134,3 @@ func (s *Server) Wait() error {
 func NewServer(config *config.Config) *Server {
 	return &Server{Config: config, errors: make(chan error, 1)}
 }
-
-func main() {
-	config, err := config.Parse()
-	if err != nil {
-		log.Fatal(err)
-	}
-	server := NewServer(config)
-	if err := server.Start(); err != nil {
-		log.Fatal(err)
-	}
-	if err := server.Wait(); err != nil {
-		log.Print(err)
-	}
-	time.Sleep(time.Second)
-}