Skip to content

Commit

Permalink
feature/v2.2.0 (#2154)
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn authored Sep 26, 2022
1 parent 9dc97f4 commit 141ca62
Show file tree
Hide file tree
Showing 147 changed files with 7,961 additions and 1,802 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/before_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

find . -name "*.go" | xargs gofmt -w
git diff --name-only --exit-code || if [ $? != 0 ]; then echo "Notice: gofmt check failed,please gofmt before pr." && exit 1; fi
echo "gofmt check pass."
sudo echo "127.0.0.1 local" | sudo tee -a /etc/hosts
40 changes: 40 additions & 0 deletions .github/workflows/build_and_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

GOARCH=${{ matrix.goarch }}
for file in `find . -name go.mod`; do
dirpath=$(dirname $file)
echo $dirpath

# package oracle needs golang >= v1.17
if [ "oracle" = $(basename $dirpath) ]; then
if ! go version|grep -q "1.17"; then
echo "ignore oracle as go version: $(go version)"
continue 1
fi
fi

# package kuhecm needs golang >= v1.18
if [ "kubecm" = $(basename $dirpath) ]; then
if ! go version|grep -q "1.18"; then
echo "ignore kubecm as go version: $(go version)"
continue 1
fi
fi

# package example needs golang >= v1.18
if [ "example" = $(basename $dirpath) ]; then
if ! go version|grep -q "1.18"; then
echo "ignore example as go version: $(go version)"
continue 1
fi
fi

cd $dirpath
go mod tidy
go build ./...
go test ./... -race -coverprofile=coverage.out -covermode=atomic -coverpkg=./...,github.com/gogf/gf/... || exit 1
if grep -q "/gogf/gf/.*/v2" go.mod; then
sed -i "s/gogf\/gf\(\/.*\)\/v2/gogf\/gf\/v2\1/g" coverage.out
fi
cd -
done
49 changes: 15 additions & 34 deletions .github/workflows/gf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
- 3306:3306

# PostgreSQL backend server.
# docker run -d --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=12345678 -e POSTGRES_USER=postgres -e POSTGRES_DB=test -v postgres:/Users/john/Temp/postgresql/data loads/postgres:13
postgres:
image: loads/postgres:13
env:
Expand Down Expand Up @@ -101,12 +102,12 @@ jobs:
- 9001:9001

polaris:
image: polarismesh/polaris-server-standalone:latest
image: loads/polaris-server-standalone:latest
ports:
- 8090:8090
- 8091:8091

#oracle 11g server
# oracle 11g server
oracle-server:
image: loads/oracle-xe-11g-r2:latest
env:
Expand All @@ -117,6 +118,11 @@ jobs:
ports:
- 1521:1521

# dm8 server
dm-server:
image: loads/dm:v8.1.2.128_ent_x86_64_ctm_pack4
ports:
- 5236:5236

strategy:
matrix:
Expand All @@ -132,6 +138,9 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Start Minikube
uses: medyagh/setup-minikube@master

- name: Setup Golang ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
Expand All @@ -140,11 +149,6 @@ jobs:
- name: Setup Golang caches
uses: actions/cache@v3
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
Expand All @@ -155,39 +159,16 @@ jobs:
${{ runner.os }}-go-${{ matrix.go-version }}-
- name: Start containers
run: docker-compose -f ".github/workflows/docker/docker-compose.yml" up -d --build
run: docker-compose -f ".github/workflows/docker/docker-compose.yml" up -d --build

- name: Before Script
run: |
find . -name "*.go" | xargs gofmt -w
git diff --name-only --exit-code || if [ $? != 0 ]; then echo "Notice: gofmt check failed,please gofmt before pr." && exit 1; fi
echo "gofmt check pass."
sudo echo "127.0.0.1 local" | sudo tee -a /etc/hosts
run: bash .github/workflows/before_script.sh

- name: Build & Test
run: |
GOARCH=${{ matrix.goarch }}
for file in `find . -name go.mod`; do
dirpath=$(dirname $file)
if [ "oracle" = $(basename $dirpath) ]; then
if ! go version|grep -q "1.17"; then
continue 1
fi
fi
cd $dirpath
go mod tidy
go build ./...
go test ./... -race -coverprofile=coverage.out -covermode=atomic -coverpkg=./...,github.com/gogf/gf/... || exit 1
if grep -q "/gogf/gf/.*/v2" go.mod; then
sed -i "s/gogf\/gf\(\/.*\)\/v2/gogf\/gf\/v2\1/g" coverage.out
fi
cd -
done
run: bash .github/workflows/build_and_test.sh

- name: Stop containers
run: docker-compose -f ".github/workflows/docker/docker-compose.yml" down
run: docker-compose -f ".github/workflows/docker/docker-compose.yml" down

- name: Report Coverage
uses: codecov/codecov-action@v2
Expand Down
1 change: 1 addition & 0 deletions container/gmap/gmap_hash_str_any_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/gogf/gf/v2/util/gconv"
)

// StrAnyMap implements map[string]interface{} with RWMutex that has switch.
type StrAnyMap struct {
mu rwmutex.RWMutex
data map[string]interface{}
Expand Down
152 changes: 152 additions & 0 deletions contrib/config/kubecm/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# kubecm
Package `kubecm` implements GoFrame `gcfg.Adapter` using kubernetes configmap.

# Limit

```go
glang version >= v.18
```

# Installation
```
go get -u github.com/gogf/gf/contrib/config/kubecm/v2
```

# Example

## Example configmap
```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: test-configmap
data:
config.yaml: |
# HTTP service.
server:
address: ":8888"
openapiPath: "/api.json"
swaggerPath: "/swagger"
accessLogEnabled: true
```
Note the configmap name `test-configmap`, and its item name in data `config.yaml`.


## Create a custom boot package

It is strongly recommended creating a boot package,
which sets the Adapter of default configuration instance.

### Running in pod (common scenario)
```go
package boot
import (
"github.com/gogf/gf/contrib/config/kubecm/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
const (
configmapName = "test-configmap"
dataItemInConfigmap = "config.yaml"
)
func init() {
var (
err error
ctx = gctx.GetInitCtx()
)
// Create kubecm Client that implements gcfg.Adapter.
adapter, err := kubecm.New(gctx.GetInitCtx(), kubecm.Config{
ConfigMap: configmapName,
DataItem: dataItemInConfigmap,
})
if err != nil {
g.Log().Fatalf(ctx, `%+v`, err)
}

// Change the adapter of default configuration instance.
g.Cfg().SetAdapter(adapter)
}
```

### Running out of pod (often testing scenario)
```go
package boot

import (
"github.com/gogf/gf/contrib/config/kubecm/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"k8s.io/client-go/kubernetes"
)

const (
namespace = "default"
configmapName = "test-configmap"
dataItemInConfigmap = "config.yaml"
kubeConfigFilePathJohn = `/Users/john/.kube/config`
)

func init() {
var (
err error
ctx = gctx.GetInitCtx()
kubeClient *kubernetes.Clientset
)
// Create kubernetes client.
// It is optional creating kube client when its is running in pod.
kubeClient, err = kubecm.NewKubeClientFromPath(ctx, kubeConfigFilePathJohn)
if err != nil {
g.Log().Fatalf(ctx, `%+v`, err)
}
// Create kubecm Client that implements gcfg.Adapter.
adapter, err := kubecm.New(gctx.GetInitCtx(), kubecm.Config{
ConfigMap: configmapName,
DataItem: dataItemInConfigmap,
Namespace: namespace, // It is optional specifying namespace when its is running in pod.
KubeClient: kubeClient, // It is optional specifying kube client when its is running in pod.
})
if err != nil {
g.Log().Fatalf(ctx, `%+v`, err)
}

// Change the adapter of default configuration instance.
g.Cfg().SetAdapter(adapter)

}
```

## Import boot package in top of main

It is strongly recommended import your boot package in top of your `main.go`.

Note the top `import`: `_ "github.com/gogf/gf/example/config/kubecm/boot_in_pod"` .

```go
package main

import (
_ "github.com/gogf/gf/example/config/kubecm/boot_in_pod"

"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)

func main() {
var ctx = gctx.GetInitCtx()

// Available checks.
g.Dump(g.Cfg().Available(ctx))

// All key-value configurations.
g.Dump(g.Cfg().Data(ctx))

// Retrieve certain value by key.
g.Dump(g.Cfg().MustGet(ctx, "server.address"))
}

```

70 changes: 70 additions & 0 deletions contrib/config/kubecm/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
module github.com/gogf/gf/contrib/config/kubecm/v2

go 1.18

require (
github.com/gogf/gf/v2 v2.0.0
k8s.io/api v0.25.2
k8s.io/apimachinery v0.25.2
k8s.io/client-go v0.25.2
)

require (
github.com/BurntSushi/toml v1.1.0 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/clbanning/mxj/v2 v2.5.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.opentelemetry.io/otel/sdk v1.7.0 // indirect
go.opentelemetry.io/otel/trace v1.7.0 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.70.1 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace github.com/gogf/gf/v2 => ../../../
Loading

0 comments on commit 141ca62

Please sign in to comment.