Skip to content

Commit

Permalink
Merge pull request #755 from georgehao/refact-seri
Browse files Browse the repository at this point in the history
Refact seri
  • Loading branch information
fangyincheng authored Sep 13, 2020
2 parents 4ccc705 + 48d746f commit b5b8c0e
Show file tree
Hide file tree
Showing 23 changed files with 2,678 additions and 106 deletions.
112 changes: 112 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: CI

on:
push:
branches: [master, develop]
pull_request:
branches: "*"

jobs:

build:
name: ${{ matrix.os }} - Go ${{ matrix.go_version }}
runs-on: ${{ matrix.os }}
strategy:
# If you want to matrix build , you can append the following list.
matrix:
go_version:
- 1.13
os:
- ubuntu-latest

env:
DING_TOKEN: "6374f1bf8d4f23cde81d4a4b8c1f0bc98cc92b5151ca938ab938d3d7f4230fc4"
DING_SIGN: "SECa98677289194bb0e5caec3051301d06515750ff1bd2f932a4704298afb2e0ae6"

steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go_version }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v2
with:
# Cache
path: ~/go/pkg/mod
# Cache key
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
# An ordered list of keys to use for restoring the cache if no cache hit occurred for key
restore-keys: |
${{ runner.os }}-go-
- name: Get dependencies
run: |
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
else
go get -v -t -d ./...
fi
- name: License Check
run: |
go fmt ./... && [[ -z `git status -s` ]]
sh before_validate_license.sh
chmod u+x /tmp/tools/license/license-header-checker
/tmp/tools/license/license-header-checker -v -a -r -i vendor /tmp/tools/license/license.txt . go && [[ -z `git status -s` ]]
- name: Test
run: |
chmod u+x before_ut.sh && ./before_ut.sh
go mod vendor && go test ./... -coverprofile=coverage.txt -covermode=atomic
chmod +x integrate_test.sh && ./integrate_test.sh
- name: Coverage
run: bash <(curl -s https://codecov.io/bash)

# Because the contexts of push and PR are different, there are two Notify.
# Notifications are triggered only in the apache/dubbo-go repository.
- name: DingTalk Message Notify only Push
uses: zcong1993/actions-ding@v3.0.1
# Whether job is successful or not, always () is always true.
if: |
always() &&
github.event_name == 'push' &&
github.repository == 'apache/dubbo-go'
with:
# DingDing bot token
dingToken: ${{ env.DING_TOKEN }}
secret: ${{ env.DING_SIGN }}
# Post Body to send
body: |
{
"msgtype": "markdown",
"markdown": {
"title": "Github Actions",
"text": "## Github Actions \n - name: CI \n - repository: ${{ github.repository }} \n - trigger: ${{ github.actor }} \n - event: ${{ github.event_name }} \n - ref: ${{ github.ref }} \n - status: [${{ job.status }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) \n - environment: ${{ runner.os }} \n - SHA: [${{ github.sha }}](${{ github.event.compare }})"
}
}
- name: DingTalk Message Notify only PR
uses: zcong1993/actions-ding@v3.0.1
if: |
always() &&
github.event_name == 'pull_request' &&
github.repository == 'apache/dubbo-go'
with:
dingToken: ${{ env.DING_TOKEN }}
secret: ${{ env.DING_SIGN }}
body: |
{
"msgtype": "markdown",
"markdown": {
"title": "Github Actions",
"text": "## Github Actions \n - name: CI \n - repository: ${{ github.repository }} \n - pr_title: ${{ github.event.pull_request.title }} \n - trigger: ${{ github.actor }} \n - event: ${{ github.event_name }} \n - ref: [${{ github.ref }}](${{ github.event.pull_request._links.html.href }}) \n - status: [${{ job.status }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) \n - environment: ${{ runner.os }} \n > SHA: [${{ github.sha }}](${{ github.event.pull_request._links.html.href }})"
}
}
79 changes: 0 additions & 79 deletions .github/workflows/go.yml

This file was deleted.

16 changes: 16 additions & 0 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ const (
NACOS_USERNAME = "username"
)

const (
FILE_KEY = "file"
)

const (
ZOOKEEPER_KEY = "zookeeper"
)
Expand All @@ -179,6 +183,18 @@ const (
ETCDV3_KEY = "etcdv3"
)

const (
CONSUL_KEY = "consul"
CHECK_PASS_INTERVAL = "consul-check-pass-interval"
// default time-to-live in millisecond
DEFAULT_CHECK_PASS_INTERVAL = 16000
QUERY_TAG = "consul_query_tag"
ACL_TOKEN = "acl-token"
// default deregister critical server after
DEFAULT_DEREGISTER_TIME = "20s"
DEREGISTER_AFTER = "consul-deregister-critical-service-after"
)

const (
TRACING_REMOTE_SPAN_CTX = "tracing.remote.span.ctx"
)
Expand Down
11 changes: 11 additions & 0 deletions common/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,17 @@ func (c *URL) AddParam(key string, value string) {
c.params.Add(key, value)
}

// AddParamAvoidNil will add key-value pair
// Not thread-safe
// think twice before using it.
func (c *URL) AddParamAvoidNil(key string, value string) {
if c.params == nil {
c.params = url.Values{}
}

c.params.Add(key, value)
}

// SetParam will put the key-value pair into url
// it's not thread safe.
// think twice before you want to use this method
Expand Down
1 change: 1 addition & 0 deletions config_center/apollo/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
)

type apolloConfiguration struct {
cc.BaseDynamicConfiguration
url *common.URL

listeners sync.Map
Expand Down
27 changes: 27 additions & 0 deletions config_center/base_dynamic_configuration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package config_center

// BaseDynamicConfiguration will default implementation DynamicConfiguration some method
type BaseDynamicConfiguration struct {
}

// RemoveConfig
func (bdc *BaseDynamicConfiguration) RemoveConfig(string, string) error {
return nil
}
3 changes: 3 additions & 0 deletions config_center/dynamic_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ type DynamicConfiguration interface {
// PublishConfig will publish the config with the (key, group, value) pair
PublishConfig(string, string, string) error

// RemoveConfig will remove the config white the (key, group) pair
RemoveConfig(string, string) error

// GetConfigKeysByGroup will return all keys with the group
GetConfigKeysByGroup(group string) (*gxset.HashSet, error)
}
Expand Down
51 changes: 51 additions & 0 deletions config_center/file/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package file

import (
perrors "github.com/pkg/errors"
)

import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/config_center"
"github.com/apache/dubbo-go/config_center/parser"
)

func init() {
extension.SetConfigCenterFactory(constant.FILE_KEY, func() config_center.DynamicConfigurationFactory {
return &fileDynamicConfigurationFactory{}
})
}

type fileDynamicConfigurationFactory struct {
}

// GetDynamicConfiguration Get Configuration with URL
func (f *fileDynamicConfigurationFactory) GetDynamicConfiguration(url *common.URL) (config_center.DynamicConfiguration,
error) {
dynamicConfiguration, err := newFileSystemDynamicConfiguration(url)
if err != nil {
return nil, perrors.WithStack(err)
}

dynamicConfiguration.SetParser(&parser.DefaultConfigurationParser{})
return dynamicConfiguration, err
}
Loading

0 comments on commit b5b8c0e

Please sign in to comment.