Skip to content

Commit

Permalink
Merge branch 'master' into v2-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
shuqingzai committed Sep 1, 2024
2 parents 25c47d5 + b9f97bd commit bf9b9fb
Show file tree
Hide file tree
Showing 43 changed files with 969 additions and 1,360 deletions.
34 changes: 28 additions & 6 deletions .github/PULL_REQUEST_TEMPLATE.MD
Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
**Please ensure you adhere to every item in this list.**
+ The PR title is formatted as follows: `os/gtime: fixed time zone issues`
+ The package name goes before the colon
+ The PR title is formatted as follows: `<type>[optional scope]: <description>` For example, `fix(os/gtime): fix time zone issue`
+ `<type>` is mandatory and can be one of `fix`, `feat`, `build`, `ci`, `docs`, `style`, `refactor`, `perf`, `test`, `chore`
+ fix: Used when a bug has been fixed.
+ feat: Used when a new feature has been added.
+ build: Used for modifications to the project build system, such as changes to dependencies, external interfaces, or upgrading Node version.
+ ci: Used for modifications to continuous integration processes, such as changes to Travis, Jenkins workflow configurations.
+ docs: Used for modifications to documentation, such as changes to README files, API documentation, etc.
+ style: Used for changes to code style, such as adjustments to indentation, spaces, blank lines, etc.
+ refactor: Used for code refactoring, such as changes to code structure, variable names, function names, without altering functionality.
+ perf: Used for performance optimization, such as improving code performance, reducing memory usage, etc.
+ test: Used for modifications to test cases, such as adding, deleting, or modifying test cases for code.
+ chore: Used for modifications to non-business-related code, such as changes to build processes or tool configurations.
+ After `<type>`, specify the affected package name or scope in parentheses, for example, `(os/gtime)`.
+ The part after the colon uses the verb tense + phrase that completes the blank in
+ Lowercase verb after the colon
+ No trailing period
+ Keep the title as short as possible. ideally under 76 characters or shorter
+ Title not Markdown
+ [Reference Documentation](https://www.conventionalcommits.org/en/v1.0.0/)
+ If there is a corresponding issue, add either `Fixes #1234` or `Updates #1234`
(the latter if this is not a complete fix) to this comment
+ Delete these instructions once you have read and applied them

**提交前请遵守每个事项,感谢!**
+ PR 标题格式如下:`os/gtime: fixed time zone issues`
+ 冒号前是包名
+ PR 标题格式如下:`<类型>[可选 范围]: <描述>` 例如 `fix(os/gtime): fix time zone issue`
+ `<类型>`是必须的,可以是 `fix``feat``build``ci``docs``style``refactor``perf``test``chore` 中的一个
+ fix: 用于修复了一个 bug
+ feat: 用于新增了一个功能
+ build: 用于修改项目构建系统,例如修改依赖库、外部接口或者升级 Node 版本等
+ ci: 用于修改持续集成流程,例如修改 Travis、Jenkins 等工作流配置
+ docs: 用于修改文档,例如修改 README 文件、API 文档等
+ style: 用于修改代码的样式,例如调整缩进、空格、空行等
+ refactor: 用于重构代码,例如修改代码结构、变量名、函数名等但不修改功能逻辑
+ perf: 用于优化性能,例如提升代码的性能、减少内存占用等
+ test: 用于修改测试用例,例如添加、删除、修改代码的测试用例等
+ chore: 用于对非业务性代码进行修改,例如修改构建流程或者工具配置等
+ `<类型>`后在括号中填写受影响的包名或范围,例如 `(os/gtime)`
+ 冒号后使用动词时态 + 短语
+ 冒号后的动词小写
+ 不要有结尾句号
+ 标题尽量保持简短,最好在 76 个字符或更短
+ 标题不要使用 Markdown
+ [参考文档](https://www.conventionalcommits.org/zh-hans/v1.0.0/)
+ 如果有对应的 issue,请在此评论中添加 `Fixes #1234`,如果不是完全修复则添加 `Updates #1234`
+ 应用这些规则后删除所有的说明
53 changes: 53 additions & 0 deletions .github/workflows/sonarcloud.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Sonarcloud Scan

on:
schedule:
# Weekly on Saturdays.
- cron: '30 1 * * 6'
push:
branches: [ master ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

# Declare default permissions as read only.
permissions: read-all

jobs:
analysis:
name: Scorecards analysis
runs-on: ubuntu-22.04
permissions:
# Needed to upload the results to code-scanning dashboard.
security-events: write
# Used to receive a badge. (Upcoming feature)
id-token: write
# Needs for private repositories.
contents: read
actions: read

steps:
- name: "Checkout code"
uses: actions/checkout@v4
with:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1
with:
results_file: results.sarif
results_format: sarif
publish_results: true

- name: "Upload artifact"
uses: actions/upload-artifact@v4
with:
name: SARIF file
path: results.sarif
retention-days: 5

- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2.2.1
with:
sarif_file: results.sarif
6 changes: 5 additions & 1 deletion cmd/gf/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DEFAULT_GOAL := pack

pack: pack.template-single pack.template-mono pack.template-mono-app

Expand All @@ -17,6 +18,9 @@ pack.template-mono:
@cd temp && gf pack template-mono ../internal/packed/template-mono.go -n=packed -y
@rm -fr temp

# Note:
# command `sed` only works on MacOS.
# use `grep -irl 'template-single' temp| xargs sed -i'' -e 's/template-single/template-mono-app/g'` on other platforms.
pack.template-mono-app:
@rm -fr temp
@mkdir temp || exit 0
Expand All @@ -27,6 +31,6 @@ pack.template-mono-app:
@rm -fr temp/template-mono-app/.gitignore
@rm -fr temp/template-mono-app/go.mod
@rm -fr temp/template-mono-app/go.sum
@sed -i 's/template-single/template-mono-app/g' temp/template-mono-app/main.go
@grep -irl 'template-single' temp| xargs sed -i '' -e 's/template-single/template-mono-app/g'
@cd temp && gf pack template-mono-app ../internal/packed/template-mono-app.go -n=packed -y
@rm -fr temp
5 changes: 3 additions & 2 deletions cmd/gf/internal/cmd/cmd_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ func (c cUp) doUpgradeVersion(ctx context.Context, in cUpInput) (out *doUpgradeV
}
for _, pkg := range packages {
mlog.Printf(`upgrading "%s" from "%s" to "latest"`, pkg.Name, pkg.Version)
// go get -u
command := fmt.Sprintf(`cd %s && go get -u %s@latest`, dirPath, pkg.Name)
mlog.Printf(`running command: go get %s@latest`, pkg.Name)
// go get @latest
command := fmt.Sprintf(`cd %s && go get %s@latest`, dirPath, pkg.Name)
if err = gproc.ShellRun(ctx, command); err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gf/internal/packed/template-mono-app.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/gf/internal/packed/template-mono.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/gf/internal/packed/template-single.go

Large diffs are not rendered by default.

130 changes: 130 additions & 0 deletions container/gtree/gtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,133 @@
//
// Some implements are from: https://github.com/emirpasic/gods
package gtree

import "github.com/gogf/gf/v2/container/gvar"

// iTree defines the interface for basic operations of a tree.
type iTree interface {
// Set inserts node into the tree.
Set(key interface{}, value interface{})

// Sets batch sets key-values to the tree.
Sets(data map[interface{}]interface{})

// SetIfNotExist sets `value` to the map if the `key` does not exist, and then returns true.
// It returns false if `key` exists, and `value` would be ignored.
SetIfNotExist(key interface{}, value interface{}) bool

// SetIfNotExistFunc sets value with return value of callback function `f`, and then returns true.
// It returns false if `key` exists, and `value` would be ignored.
SetIfNotExistFunc(key interface{}, f func() interface{}) bool

// SetIfNotExistFuncLock sets value with return value of callback function `f`, and then returns true.
// It returns false if `key` exists, and `value` would be ignored.
// SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that
// it executes function `f` with mutex.Lock of the hash map.
SetIfNotExistFuncLock(key interface{}, f func() interface{}) bool

// Get searches the node in the tree by `key` and returns its value or nil if key is not found in tree.
Get(key interface{}) (value interface{})

// GetOrSet returns the value by key,
// or sets value with given `value` if it does not exist and then returns this value.
GetOrSet(key interface{}, value interface{}) interface{}

// GetOrSetFunc returns the value by key,
// or sets value with returned value of callback function `f` if it does not exist
// and then returns this value.
GetOrSetFunc(key interface{}, f func() interface{}) interface{}

// GetOrSetFuncLock returns the value by key,
// or sets value with returned value of callback function `f` if it does not exist
// and then returns this value.
// GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function `f`
// with mutex.Lock of the hash map.
GetOrSetFuncLock(key interface{}, f func() interface{}) interface{}

// GetVar returns a gvar.Var with the value by given `key`.
// The returned gvar.Var is un-concurrent safe.
GetVar(key interface{}) *gvar.Var

// GetVarOrSet returns a gvar.Var with result from GetVarOrSet.
// The returned gvar.Var is un-concurrent safe.
GetVarOrSet(key interface{}, value interface{}) *gvar.Var

// GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc.
// The returned gvar.Var is un-concurrent safe.
GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var

// GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock.
// The returned gvar.Var is un-concurrent safe.
GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var

// Search searches the tree with given `key`.
// Second return parameter `found` is true if key was found, otherwise false.
Search(key interface{}) (value interface{}, found bool)

// Contains checks whether `key` exists in the tree.
Contains(key interface{}) bool

// Size returns number of nodes in the tree.
Size() int

// IsEmpty returns true if tree does not contain any nodes.
IsEmpty() bool

// Remove removes the node from the tree by key.
// Key should adhere to the comparator's type assertion, otherwise method panics.
Remove(key interface{}) (value interface{})

// Removes batch deletes values of the tree by `keys`.
Removes(keys []interface{})

// Clear removes all nodes from the tree.
Clear()

// Keys returns all keys in asc order.
Keys() []interface{}

// Values returns all values in asc order based on the key.
Values() []interface{}

// Replace the data of the tree with given `data`.
Replace(data map[interface{}]interface{})

// Print prints the tree to stdout.
Print()

// String returns a string representation of container
String() string

// MarshalJSON implements the interface MarshalJSON for json.Marshal.
MarshalJSON() (jsonBytes []byte, err error)

Map() map[interface{}]interface{}
MapStrAny() map[string]interface{}

// Iterator is alias of IteratorAsc.
Iterator(f func(key, value interface{}) bool)

// IteratorFrom is alias of IteratorAscFrom.
IteratorFrom(key interface{}, match bool, f func(key, value interface{}) bool)

// IteratorAsc iterates the tree readonly in ascending order with given callback function `f`.
// If `f` returns true, then it continues iterating; or false to stop.
IteratorAsc(f func(key, value interface{}) bool)

// IteratorAscFrom iterates the tree readonly in ascending order with given callback function `f`.
// The parameter `key` specifies the start entry for iterating. The `match` specifies whether
// starting iterating if the `key` is fully matched, or else using index searching iterating.
// If `f` returns true, then it continues iterating; or false to stop.
IteratorAscFrom(key interface{}, match bool, f func(key, value interface{}) bool)

// IteratorDesc iterates the tree readonly in descending order with given callback function `f`.
// If `f` returns true, then it continues iterating; or false to stop.
IteratorDesc(f func(key, value interface{}) bool)

// IteratorDescFrom iterates the tree readonly in descending order with given callback function `f`.
// The parameter `key` specifies the start entry for iterating. The `match` specifies whether
// starting iterating if the `key` is fully matched, or else using index searching iterating.
// If `f` returns true, then it continues iterating; or false to stop.
IteratorDescFrom(key interface{}, match bool, f func(key, value interface{}) bool)
}
Loading

0 comments on commit bf9b9fb

Please sign in to comment.