Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Migration to sub command #118

Merged
merged 8 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions application/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ func (c *Configuration) Set(path string) error {
return yaml.NewDecoder(bytes.NewReader(data)).Decode(c)
}

// Type returns value type of itself
func (c *Configuration) Type() string {
return "string"
}

// Addr returns a string of server port
func (c *Configuration) Addr() string {
return fmt.Sprintf(":%d", c.Server.Port)
Expand Down
10 changes: 10 additions & 0 deletions application/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ func TestConfiguration_Set(t *testing.T) {
})
}

func TestConfiguration_Type(t *testing.T) {
// when
actual := application.Config.Type()

// expect
if actual != "string" {
t.Errorf("type should equal string, but got %+v", actual)
}
}

func TestConfiguration_Addr(t *testing.T) {
// given
application.Config.Server.Port = 8823
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.0.0 // indirect
github.com/sirupsen/logrus v1.0.6 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3 // indirect
github.com/src-d/gcfg v1.3.0 // indirect
github.com/stretchr/testify v1.2.2 // indirect
github.com/syndtr/goleveldb v0.0.0-20180815032940-ae2bd5eed72d
Expand Down
21 changes: 17 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
package main

import (
"flag"
"github.com/duck8823/duci/application"
"github.com/duck8823/duci/application/semaphore"
"github.com/duck8823/duci/infrastructure/logger"
"github.com/duck8823/duci/presentation/router"
"github.com/google/uuid"
"github.com/spf13/cobra"
"net/http"
"os"
)

func main() {
mainID := uuid.New()
serverCmd := &cobra.Command{
Use: "server",
Run: serverCmd,
}
serverCmd.PersistentFlags().VarP(application.Config, "config", "c", "configuration file path")

rootCmd := &cobra.Command{Use: "duci"}
rootCmd.AddCommand(serverCmd)

if err := rootCmd.Execute(); err != nil {
logger.Errorf(uuid.New(), "Failed to execute command.\n%+v", err)
os.Exit(1)
}
}

flag.Var(application.Config, "c", "configuration file path")
flag.Parse()
func serverCmd(cmd *cobra.Command, _ []string) {
mainID := uuid.New()

if err := semaphore.Make(); err != nil {
logger.Errorf(mainID, "Failed to initialize a semaphore.\n%+v", err)
Expand Down