created init client method and init command
This commit is contained in:
BIN
chub/.DS_Store
vendored
Normal file
BIN
chub/.DS_Store
vendored
Normal file
Binary file not shown.
14
chub/client/init.go
Normal file
14
chub/client/init.go
Normal file
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
8
chub/client/machine.go
Normal file
8
chub/client/machine.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package client
|
||||
|
||||
type Machine struct {
|
||||
Hostname string
|
||||
Platform string
|
||||
Architecture string
|
||||
MachineGuid string
|
||||
}
|
||||
BIN
chub/globals/.DS_Store
vendored
Normal file
BIN
chub/globals/.DS_Store
vendored
Normal file
Binary file not shown.
8
chub/globals/globals.go
Normal file
8
chub/globals/globals.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package globals
|
||||
|
||||
const (
|
||||
ConfigurationFolderName = ".chub"
|
||||
ConfigurationFilePermissions = 600
|
||||
ConfigurationFileName = "config"
|
||||
UrlOfTheService = "confighub.meteor.com"
|
||||
)
|
||||
36
chub/init.go
36
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 ?")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user