diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..427cbce Binary files /dev/null and b/.DS_Store differ diff --git a/chub/.DS_Store b/chub/.DS_Store new file mode 100644 index 0000000..a56625f Binary files /dev/null and b/chub/.DS_Store differ diff --git a/chub/client/init.go b/chub/client/init.go new file mode 100644 index 0000000..3f5c9db --- /dev/null +++ b/chub/client/init.go @@ -0,0 +1,14 @@ +package client + +import ( + "io/ioutil" + "net/http" +) + +func Init(machine *Machine) { + req, err := http.NewRequest("POST", url, nil) + if err != nil { + return nil, err + } + +} diff --git a/chub/client/machine.go b/chub/client/machine.go new file mode 100644 index 0000000..7b6c05e --- /dev/null +++ b/chub/client/machine.go @@ -0,0 +1,8 @@ +package client + +type Machine struct { + Hostname string + Platform string + Architecture string + MachineGuid string +} diff --git a/chub/globals/.DS_Store b/chub/globals/.DS_Store new file mode 100644 index 0000000..53fa1c4 Binary files /dev/null and b/chub/globals/.DS_Store differ diff --git a/chub/globals/globals.go b/chub/globals/globals.go new file mode 100644 index 0000000..ca38a66 --- /dev/null +++ b/chub/globals/globals.go @@ -0,0 +1,8 @@ +package globals + +const ( + ConfigurationFolderName = ".chub" + ConfigurationFilePermissions = 600 + ConfigurationFileName = "config" + UrlOfTheService = "confighub.meteor.com" +) diff --git a/chub/init.go b/chub/init.go index 694c078..5125e10 100644 --- a/chub/init.go +++ b/chub/init.go @@ -1,11 +1,43 @@ package main import ( - "fmt" + "chub/client" + "encoding/json" + homedir "github.com/mitchellh/go-homedir" + "io/ioutil" + "os" + "path/filepath" + "runtime" ) func initCommand(guid string) { + confguration := config{MachineGuid: guid} + saveGuidToHomedir(configuration) - fmt.Printf("initializing %v\n", guid) + machineToInitialize := client.Machine{os.Hostname(), runtime.GOOS, runtime.GOARCH, guid} + client.init(&machineToInitialize) + +} + +type config struct { + MachineGuid string +} + +func saveGuidToHomedir(configuration config) { + + directory := homedir.Expand() + filepath.Separator + ConfigurationFolderName + if err := os.Mkdir(directory, ConfigurationFilePermissions); err != nil { + panic(err) + } + + configByteContent, err := json.Marshal(configuration) + if err != nil { + panic("Something is terribly wrong. I am sorry. I am so so sorry. :~(") + } + + err := ioutil.WriteFile(directory+filepath.Separator+ConfigurationFileName, configByteContent, ConfigurationFilePermissions) + if err != nil { + panic("I cannot write to config file in user directory. How can this be ?") + } }