Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
verdverm committed May 9, 2020
1 parent 958e0a5 commit d1d895e
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 5 deletions.
72 changes: 70 additions & 2 deletions .hof/Cli/cmd/mvs/ga/ga.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
package ga

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/google/uuid"
"github.com/hofstadter-io/yagu"

"github.com/hofstadter-io/mvs/cmd/mvs/verinfo"
)

func SendGaEvent(action, label string, value int) {
// Do something here to lookup / create
cid := "13b3ad64-9154-11ea-9eba-47f617ab74f7"
// cid := "13b3ad64-9154-11ea-9eba-47f617ab74f7"
cid, err := readGaId()
if err != nil {
fmt.Println("Error", err)
cid = "unknown"
}

fmt.Println("CID:", cid)

cfg := yagu.GaConfig{
TID: "UA-103579574-5",
CID: cid,
UA: "mvs/" + verinfo.Version,
CN: "mvs",
CS: "mvs",
CN: verinfo.Version,
CM: verinfo.Version,
}

evt := yagu.GaEvent{
Expand All @@ -31,3 +45,57 @@ func SendGaEvent(action, label string, value int) {

yagu.SendGaEvent(cfg, evt)
}

func readGaId() (string, error) {
ucd := yagu.UserHomeDir()
dir := filepath.Join(ucd, ".hof")
fn := filepath.Join(dir, ".uuid")

_, err := os.Lstat(fn)
if err != nil {
// make sure we check err for something actually bad
if _, ok := err.(*os.PathError); !ok && err.Error() != "file does not exist" {
// return "", err
}
// file does not exist
return writeGaId()
}

content, err := ioutil.ReadFile(fn)
if err != nil {
fmt.Println("ERROR:", err)
return writeGaId()
// return "", err
}

return string(content), nil
}

func writeGaId() (string, error) {
fmt.Println("writeGaId")
ucd := yagu.UserHomeDir()

dir := filepath.Join(ucd, ".hof")
err := yagu.Mkdir(dir)
if err != nil {
return "", err
}

fmt.Println("Mkdir:", dir)

fn := filepath.Join(dir, ".uuid")

id, err := uuid.NewUUID()
if err != nil {
return id.String(), err
}

fmt.Println("writeGaId: ", id.String())

err = ioutil.WriteFile(fn, []byte(id.String()), 0644)
if err != nil {
return id.String(), err
}

return id.String(), nil
}
1 change: 1 addition & 0 deletions cli.cue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ HofGenCli: gen.#HofGenerator & {
}

Telemetry: "UA-103579574-5"
TelemetryIdDir: ".hof"

OmitRun: true

Expand Down
72 changes: 70 additions & 2 deletions cmd/mvs/ga/ga.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
package ga

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/google/uuid"
"github.com/hofstadter-io/yagu"

"github.com/hofstadter-io/mvs/cmd/mvs/verinfo"
)

func SendGaEvent(action, label string, value int) {
// Do something here to lookup / create
cid := "13b3ad64-9154-11ea-9eba-47f617ab74f7"
// cid := "13b3ad64-9154-11ea-9eba-47f617ab74f7"
cid, err := readGaId()
if err != nil {
fmt.Println("Error", err)
cid = "unknown"
}

fmt.Println("CID:", cid)

cfg := yagu.GaConfig{
TID: "UA-103579574-5",
CID: cid,
UA: "mvs/" + verinfo.Version,
CN: "mvs",
CS: "mvs",
CN: verinfo.Version,
CM: verinfo.Version,
}

evt := yagu.GaEvent{
Expand All @@ -31,3 +45,57 @@ func SendGaEvent(action, label string, value int) {

yagu.SendGaEvent(cfg, evt)
}

func readGaId() (string, error) {
ucd := yagu.UserHomeDir()
dir := filepath.Join(ucd, ".hof")
fn := filepath.Join(dir, ".uuid")

_, err := os.Lstat(fn)
if err != nil {
// make sure we check err for something actually bad
if _, ok := err.(*os.PathError); !ok && err.Error() != "file does not exist" {
// return "", err
}
// file does not exist
return writeGaId()
}

content, err := ioutil.ReadFile(fn)
if err != nil {
fmt.Println("ERROR:", err)
return writeGaId()
// return "", err
}

return string(content), nil
}

func writeGaId() (string, error) {
fmt.Println("writeGaId")
ucd := yagu.UserHomeDir()

dir := filepath.Join(ucd, ".hof")
err := yagu.Mkdir(dir)
if err != nil {
return "", err
}

fmt.Println("Mkdir:", dir)

fn := filepath.Join(dir, ".uuid")

id, err := uuid.NewUUID()
if err != nil {
return id.String(), err
}

fmt.Println("writeGaId: ", id.String())

err = ioutil.WriteFile(fn, []byte(id.String()), 0644)
if err != nil {
return id.String(), err
}

return id.String(), nil
}
2 changes: 1 addition & 1 deletion cue.mods
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ module github.com/hofstadter-io/mvs
cue master

require (
github.com/hofstadter-io/hofmod-cli v0.5.0
github.com/hofstadter-io/hofmod-cli v0.5.1
)
2 changes: 2 additions & 0 deletions cue.sums
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ github.com/hofstadter-io/hofmod-cli v0.4.0 h1:M9qmHyUW9AxmOAgeAwbfa24L3+GBAuiBhb
github.com/hofstadter-io/hofmod-cli v0.4.0/cue.mods h1:8TVLRMLOvfcVRZu6NqDr4VFmvuw/9Ca7YpCMo1fTRmU=
github.com/hofstadter-io/hofmod-cli v0.5.0 h1:hZT2BUWJftP9jq32bcOElXg1N9oXEFJCK9MxBmfS+24=
github.com/hofstadter-io/hofmod-cli v0.5.0/cue.mods h1:8TVLRMLOvfcVRZu6NqDr4VFmvuw/9Ca7YpCMo1fTRmU=
github.com/hofstadter-io/hofmod-cli v0.5.1 h1:a8Zworm73OyAUxtVPEzibspP5kImka/3D+CwHQ9cz+E=
github.com/hofstadter-io/hofmod-cli v0.5.1/cue.mods h1:8TVLRMLOvfcVRZu6NqDr4VFmvuw/9Ca7YpCMo1fTRmU=
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/go-git/go-billy/v5 v5.0.0
github.com/go-git/go-git/v5 v5.0.0
github.com/google/go-github/v30 v30.1.0
github.com/google/uuid v1.1.1
github.com/hofstadter-io/yagu v0.0.1
github.com/parnurzeal/gorequest v0.2.16
github.com/spf13/cobra v1.0.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ github.com/google/go-github/v30 v30.1.0 h1:VLDx+UolQICEOKu2m4uAoMti1SxuEBAl7RSEG
github.com/google/go-github/v30 v30.1.0/go.mod h1:n8jBpHl45a/rlBUtRJMOG4GhNADUQFEufcolZ95JfU8=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
Expand Down

0 comments on commit d1d895e

Please sign in to comment.