Skip to content

Commit

Permalink
增加了一些新的测试demo
Browse files Browse the repository at this point in the history
包括gormgen生成、casbinredis 等
  • Loading branch information
peifengll committed Dec 11, 2023
1 parent a2ffe21 commit c4acc1c
Show file tree
Hide file tree
Showing 193 changed files with 23,058 additions and 72 deletions.
27 changes: 17 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ require (
github.com/casbin/casbin/v2 v2.77.2
github.com/casbin/gorm-adapter/v3 v3.0.4
github.com/gin-gonic/gin v1.9.1
github.com/go-redis/redis/v8 v8.11.5
github.com/google/martian v2.1.0+incompatible
github.com/prometheus/client_golang v1.17.0
github.com/spf13/viper v1.17.0
github.com/zeromicro/go-zero v1.6.0
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
gorm.io/driver/mysql v1.5.2
gorm.io/gen v0.3.24
gorm.io/gorm v1.25.5
gorm.io/plugin/dbresolver v1.5.0
)

require (
Expand All @@ -32,7 +36,6 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
Expand All @@ -46,13 +49,13 @@ require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.1 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgtype v1.12.0 // indirect
github.com/jackc/pgx/v4 v4.17.2 // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lib/pq v1.10.2 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand All @@ -63,7 +66,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/openzipkin/zipkin-go v0.4.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
Expand Down Expand Up @@ -93,18 +95,23 @@ require (
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.4.4 // indirect
gorm.io/datatypes v1.2.0 // indirect
gorm.io/driver/postgres v1.5.0 // indirect
gorm.io/driver/sqlserver v1.4.1 // indirect
gorm.io/hints v1.1.2 // indirect
)
98 changes: 66 additions & 32 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions gps-district-service/gpsquery.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gps-district-service/gpsquery_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ctlmodel:
cd testgorm/testgen/gendemo2/ && go run generate.go
26 changes: 26 additions & 0 deletions prometheus/instrument-demo/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
"time"
)

func main() {
temp := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "home_temperature_celsius",
Help: "The current temperature in degrees Celsius.",
})
prometheus.MustRegister(temp)
temp.Set(39)
go func() {
for {
temp.Add(4)
time.Sleep(50000)
}
}()
// Serve the default Prometheus metrics registry over HTTP on /metrics.
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":8080", nil)
}
29 changes: 29 additions & 0 deletions prometheus/instrument-demo/main2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
)

// 使用、暴露和创建一个非全局注册对象
func main() {
registry := prometheus.NewRegistry()
// 添加process和go运行时指标到自定义的注册表中
//registry.MustRegister(prometheus.NewProcessCollector(
// prometheus.ProcessCollectorOpts{}))
//registry.MustRegister(prometheus.NewGoCollector())
// 创建一个简单的gauge指标
temp := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "home_temperature_celsius",
Help: "The current temperature in degrees Celsius.",
})
registry.MustRegister(temp)
temp.Set(39)

http.Handle("/metrics", promhttp.HandlerFor(registry, promhttp.HandlerOpts{
Registry: registry,
}))
http.ListenAndServe(":8080", nil)

}
16 changes: 7 additions & 9 deletions testgasbin/8.deny/model.conf
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
[role_definition]
g = _,_


[matchers]
m= g ( r.sub,p.sub) && r.obj == p.obj &&r.act ==p.act


[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act,eft


[role_definition]
g = _,_

[policy_effect]
e = some(where (p.eft == allow)) && !some(where (p.eft == deny))
e = some(where (p.eft == allow)) && !some(where (p.eft == deny))

[matchers]
m= g ( r.sub,p.sub) && r.obj == p.obj &&r.act ==p.act
1 change: 1 addition & 0 deletions testgasbin/others_demo/casbin-redis-adapter
Submodule casbin-redis-adapter added at 90e577
30 changes: 30 additions & 0 deletions testgasbin/others_demo/casbin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof

.idea/
*.iml

# vendor files
vendor
16 changes: 16 additions & 0 deletions testgasbin/others_demo/casbin/.releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"debug": true,
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"master",
{
"name": "beta",
"prerelease": true
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/github"
]
}
15 changes: 15 additions & 0 deletions testgasbin/others_demo/casbin/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: go

sudo: false

env:
- GO111MODULE=on

go:
- "1.11.13"
- "1.12"
- "1.13"
- "1.14"

script:
- make test
35 changes: 35 additions & 0 deletions testgasbin/others_demo/casbin/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# How to contribute

The following is a set of guidelines for contributing to casbin and its libraries, which are hosted at [casbin organization at Github](https://github.com/casbin).

This project adheres to the [Contributor Covenant 1.2.](https://www.contributor-covenant.org/version/1/2/0/code-of-conduct.html) By participating, you are expected to uphold this code. Please report unacceptable behavior to [email protected].

## Questions

- We do our best to have an [up-to-date documentation](https://casbin.org/docs/overview)
- [Stack Overflow](https://stackoverflow.com) is the best place to start if you have a question. Please use the [casbin tag](https://stackoverflow.com/tags/casbin/info) we are actively monitoring. We encourage you to use Stack Overflow specially for Modeling Access Control Problems, in order to build a shared knowledge base.
- You can also join our [Discord](https://discord.gg/S5UjpzGZjN).

## Reporting issues

Reporting issues are a great way to contribute to the project. We are perpetually grateful about a well-written, through bug report.

Before raising a new issue, check our [issue list](https://github.com/casbin/casbin/issues) to determine if it already contains the problem that you are facing.

A good bug report shouldn't leave others needing to chase you for more information. Please be as detailed as possible. The following questions might serve as a template for writing a detailed report:

What were you trying to achieve?
What are the expected results?
What are the received results?
What are the steps to reproduce the issue?
In what environment did you encounter the issue?

Feature requests can also be submitted as issues.

## Pull requests

Good pull requests (e.g. patches, improvements, new features) are a fantastic help. They should remain focused in scope and avoid unrelated commits.

Please ask first before embarking on any significant pull request (e.g. implementing new features, refactoring code etc.), otherwise you risk spending a lot of time working on something that the maintainers might not want to merge into the project.

First add an issue to the project to discuss the improvement. Please adhere to the coding conventions used throughout the project. If in doubt, consult the [Effective Go style guide](https://golang.org/doc/effective_go.html).
Loading

0 comments on commit c4acc1c

Please sign in to comment.