Skip to content

Commit

Permalink
ui.envelope and ui.Envelope structs were very similar, let's use just…
Browse files Browse the repository at this point in the history
… one.
  • Loading branch information
xiam committed Feb 22, 2015
1 parent fc172ac commit 93e3e08
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func Configure(cfg *proxiedsites.Config) {
} else if delta != nil {
// Sending delta.
message := ui.Envelope{
Type: messageType,
Message: delta,
EnvelopeType: ui.EnvelopeType{messageType},
Message: delta,
}
b, err := json.Marshal(message)

Expand Down
6 changes: 5 additions & 1 deletion src/github.com/getlantern/flashlight/ui/envelope.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package ui

type EnvelopeType struct {
Type string
}

// Envelope is a struct that wraps messages and associates them with a type.
type Envelope struct {
Type string
EnvelopeType
Message interface{}
}
18 changes: 4 additions & 14 deletions src/github.com/getlantern/flashlight/ui/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ import (
"sync"
)

type envelopeType struct {
Type string
}

// envelope is a struct that wraps messages and associates them with a type.
type envelope struct {
envelopeType
Message interface{}
}

type helloFnType func(func(interface{}) error) error

type Service struct {
Expand Down Expand Up @@ -121,7 +111,7 @@ func read() {
// Reading from the combined input.
for b := range defaultUIChannel.In {
// Determining message type.
var envType envelopeType
var envType EnvelopeType
err := json.Unmarshal(b, &envType)

if err != nil {
Expand All @@ -135,7 +125,7 @@ func read() {
return
}

env := &envelope{}
env := &Envelope{}
err = json.Unmarshal(b, env)
if err != nil {
log.Errorf("Unable to unmarshal message of type %v: %v", envType.Type, err)
Expand All @@ -147,8 +137,8 @@ func read() {
}

func newEnvelope(t string, msg interface{}) ([]byte, error) {
b, err := json.Marshal(&envelope{
envelopeType: envelopeType{t},
b, err := json.Marshal(&Envelope{
EnvelopeType: EnvelopeType{t},
Message: msg,
})
if err != nil {
Expand Down

0 comments on commit 93e3e08

Please sign in to comment.