-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from topfreegames/chore/migrate-fcm
Migrate from legacy gcm to Firebase
- Loading branch information
Showing
34 changed files
with
1,879 additions
and
1,146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
MOCKGENERATE := go run github.com/golang/mock/mockgen@v1.7.0-rc.1 | ||
MOCKGENERATE := go run go.uber.org/mock/mockgen@v0.4.0 | ||
GINKGO := go run github.com/onsi/ginkgo/[email protected] | ||
|
||
build: | ||
|
@@ -46,7 +46,7 @@ run: | |
@go run main.go | ||
|
||
gcm: | ||
@go run main.go gcm --senderId=test --apiKey=123 | ||
@go run main.go gcm | ||
|
||
apns: | ||
@go run main.go apns --certificate=./tls/_fixtures/certificate-valid.pem | ||
|
@@ -105,7 +105,7 @@ test-unit: | |
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" | ||
@echo | ||
@export $ACK_GINKGO_RC=true | ||
@$(GINKGO) -trace -r --randomizeAllSpecs --randomizeSuites --cover --focus="\[Unit\].*" . | ||
@$(GINKGO) --race -trace -r --randomizeAllSpecs --randomizeSuites --cover --focus="\[Unit\].*" . | ||
@$(MAKE) test-coverage-func | ||
@echo | ||
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" | ||
|
@@ -120,7 +120,7 @@ run-integration-test: | |
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" | ||
@echo | ||
@export $ACK_GINKGO_RC=true | ||
@$(GINKGO) -trace -r -tags=integration --randomizeAllSpecs --randomizeSuites --focus="\[Integration\].*" . | ||
@$(GINKGO) --race -trace -r -tags=integration --randomizeAllSpecs --randomizeSuites --focus="\[Integration\].*" . | ||
@echo | ||
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" | ||
@echo "= Integration tests finished. =" | ||
|
@@ -171,6 +171,6 @@ integration-test-container-dev: build-image-dev start-deps-container-dev test-db | |
pusher:local make run-integration-test | ||
@$(MAKE) stop-deps | ||
|
||
# .PHONY: mocks | ||
# mocks: | ||
# $(MOCKGENERATE) -package=mocks -source=interfaces/apns.go -destination=mocks/apns.go | ||
.PHONY: mocks | ||
mocks: | ||
$(MOCKGENERATE) -source=interfaces/client.go -destination=mocks/firebase/client.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/mitchellh/mapstructure" | ||
"github.com/spf13/viper" | ||
"github.com/topfreegames/pusher/util" | ||
"reflect" | ||
"strings" | ||
) | ||
|
||
type ( | ||
// Config is the struct that holds all the configuration for the Pusher. | ||
Config struct { | ||
GCM GCM | ||
GracefulShutdownTimeout int | ||
} | ||
|
||
GCM struct { | ||
Apps string | ||
PingInterval int | ||
PingTimeout int | ||
MaxPendingMessages int | ||
LogStatsInterval int | ||
} | ||
) | ||
|
||
// NewConfigAndViper returns a new Config object and the corresponding viper instance. | ||
func NewConfigAndViper(configFile string) (*Config, *viper.Viper, error) { | ||
v, err := util.NewViperWithConfigFile(configFile) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
if err := v.ReadInConfig(); err != nil { | ||
return nil, nil, fmt.Errorf("error reading config file from %s: %s", configFile, err) | ||
} | ||
|
||
config := &Config{} | ||
if err := v.Unmarshal(config, decodeHookFunc()); err != nil { | ||
return nil, nil, fmt.Errorf("error unmarshalling config: %s", err) | ||
} | ||
|
||
return config, v, nil | ||
} | ||
|
||
func (c *Config) GetAppsArray() []string { | ||
arr := strings.Split(c.GCM.Apps, ",") | ||
res := make([]string, 0, len(arr)) | ||
for _, a := range arr { | ||
res = append(res, strings.TrimSpace(a)) | ||
} | ||
|
||
return res | ||
} | ||
|
||
func decodeHookFunc() viper.DecoderConfigOption { | ||
hooks := mapstructure.ComposeDecodeHookFunc( | ||
StringToMapStringHookFunc(), | ||
) | ||
return viper.DecodeHook(hooks) | ||
} | ||
|
||
func StringToMapStringHookFunc() mapstructure.DecodeHookFunc { | ||
return func( | ||
f reflect.Type, | ||
t reflect.Type, | ||
data interface{}, | ||
) (interface{}, error) { | ||
if f.Kind() != reflect.String || t.Kind() != reflect.Map { | ||
return data, nil | ||
} | ||
|
||
if t.Key().Kind() != reflect.String || t.Elem().Kind() != reflect.String { | ||
return data, nil | ||
} | ||
|
||
raw := data.(string) | ||
if raw == "" { | ||
return map[string]string{}, nil | ||
} | ||
|
||
m := map[string]string{} | ||
err := json.Unmarshal([]byte(raw), &m) | ||
return m, err | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.