From 3f0c2267c5c552ded616e311786821cc30b538bc Mon Sep 17 00:00:00 2001 From: Mikhail Knyazhev Date: Mon, 22 Sep 2025 00:56:55 +0300 Subject: [PATCH] go1.24 --- .github/dependabot.yml | 0 .github/workflows/ci.yml | 2 +- .github/workflows/codeql.yml | 38 ---- .gitignore | 21 +- .golangci.yml | 389 ++++------------------------------- .lic.yaml | 2 +- LICENSE | 2 +- Makefile | 20 +- application.go | 11 +- application_test.go | 23 ++- config/config.go | 2 +- container/container.go | 9 +- container/container_test.go | 17 +- container/storage.go | 2 +- env/envs.go | 2 +- errs/errors.go | 2 +- go.mod | 17 +- go.sum | 30 +-- internal/utils.go | 2 +- logger.go | 17 +- modules.go | 2 +- modules_test.go | 3 +- reflect/reflect.go | 17 +- reflect/reflect_test.go | 4 +- services/services.go | 11 +- 25 files changed, 154 insertions(+), 491 deletions(-) mode change 100644 => 100755 .github/dependabot.yml mode change 100644 => 100755 .github/workflows/ci.yml delete mode 100644 .github/workflows/codeql.yml mode change 100644 => 100755 .gitignore mode change 100644 => 100755 .golangci.yml mode change 100644 => 100755 Makefile diff --git a/.github/dependabot.yml b/.github/dependabot.yml old mode 100644 new mode 100755 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml old mode 100644 new mode 100755 index 8ddfece..a76bd9e --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: [ '1.21' ] + go: [ '1.24' ] steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index ddee4f0..0000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,38 +0,0 @@ - -name: "CodeQL" - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - schedule: - - cron: '16 8 * * 1' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'go' ] - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - with: - category: "/language:${{matrix.language}}" diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index 37e78f6..2d09f4d --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,12 @@ + +.tools/ +bin/ +vendor/ +build/ +.idea/ +.vscode/ +coverage.txt +coverage.out *.exe *.exe~ *.dll @@ -8,14 +17,4 @@ *.mmdb *.test *.out - -.idea/ -.vscode/ -.tools/ - -coverage.txt -coverage.out - -bin/ -vendor/ -build/ +.env \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml old mode 100644 new mode 100755 index 0e583a4..60f1183 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,375 +1,68 @@ +version: "2" -# options for analysis running run: - # timeout for analysis, e.g. 30s, 5m, default is 1m - deadline: 5m - - # exit code when at least one issue was found, default is 1 - issues-exit-code: 1 - - # include test files or not, default is true + go: "1.24" + timeout: 5m tests: false - - # which files to skip: they will be analyzed, but issues from them - # won't be reported. Default value is empty list, but there is - # no need to include all autogenerated files, we confidently recognize - # autogenerated files. If it's not please let us know. - skip-files: - - easyjson + issues-exit-code: 1 + modules-download-mode: readonly + allow-parallel-runners: true issues: - # Independently from option 'exclude' we use default exclude patterns, - # it can be disabled by this option. To list all - # excluded by default patterns execute 'golangci-lint run --help'. - # Default value for this option is true. - exclude-use-default: false - # Excluding configuration per-path, per-linter, per-text and per-source - exclude-rules: - # Exclude some linters from running on tests files. - - path: _test\.go - linters: - - prealloc - - errcheck + max-issues-per-linter: 0 + max-same-issues: 0 + new: false + fix: false -# output configuration options output: - # colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number" - format: colored-line-number - - # print lines of code with issue, default is true - print-issued-lines: true + formats: + text: + print-linter-name: true + print-issued-lines: true - # print linter name in the end of issue text, default is true - print-linter-name: true - -# all available settings of specific linters -linters-settings: - govet: - # report about shadowed variables - check-shadowing: true +formatters: + exclusions: + paths: + - vendors/ enable: - # report mismatches between assembly files and Go declarations - - asmdecl - # check for useless assignments - - assign - # check for common mistakes using the sync/atomic package - - atomic - # check for non-64-bits-aligned arguments to sync/atomic functions - - atomicalign - # check for common mistakes involving boolean operators - - bools - # check that +build tags are well-formed and correctly located - - buildtag - # detect some violations of the cgo pointer passing rules - - cgocall - # check for unkeyed composite literals - - composites - # check for locks erroneously passed by value - - copylocks - # check for calls of reflect.DeepEqual on error values - - deepequalerrors - # report passing non-pointer or non-error values to errors.As - - errorsas - # find calls to a particular function - - findcall - # report assembly that clobbers the frame pointer before saving it - - framepointer - # check for mistakes using HTTP responses - - httpresponse - # detect impossible interface-to-interface type assertions - - ifaceassert - # check references to loop variables from within nested functions - - loopclosure - # check cancel func returned by context.WithCancel is called - - lostcancel - # check for useless comparisons between functions and nil - - nilfunc - # check for redundant or impossible nil comparisons - - nilness - # check consistency of Printf format strings and arguments - - printf - # check for comparing reflect.Value values with == or reflect.DeepEqual - - reflectvaluecompare - # check for possible unintended shadowing of variables - - shadow - # check for shifts that equal or exceed the width of the integer - - shift - # check for unbuffered channel of os.Signal - - sigchanyzer - # check the argument type of sort.Slice - - sortslice - # check signature of methods of well-known interfaces - - stdmethods - # check for string(int) conversions - - stringintconv - # check that struct field tags conform to reflect.StructTag.Get - - structtag - # report calls to (*testing.T).Fatal from goroutines started by a test. - - testinggoroutine - # check for common mistaken usages of tests and examples - - tests - # report passing non-pointer or non-interface values to unmarshal - - unmarshal - # check for unreachable code - - unreachable - # check for invalid conversions of uintptr to unsafe.Pointer - - unsafeptr - # check for unused results of calls to some functions - - unusedresult - # checks for unused writes - - unusedwrite - disable: - # find structs that would use less memory if their fields were sorted - - fieldalignment - gofmt: - # simplify code: gofmt with '-s' option, true by default - simplify: true - errcheck: - # report about not checking of errors in type assetions: 'a := b.(MyStruct)'; - # default is false: such cases aren't reported by default. - check-type-assertions: true - # report about assignment of errors to blank identifier: 'num, _ := strconv.Atoi(numStr)'; - # default is false: such cases aren't reported by default. - check-blank: true - gocyclo: - # minimal code complexity to report, 30 by default (but we recommend 10-20) - min-complexity: 15 - misspell: - # Correct spellings using locale preferences for US or UK. - # Default is to use a neutral variety of English. - # Setting locale to US will correct the British spelling of 'colour' to 'color'. - locale: US - prealloc: - # XXX: we don't recommend using this linter before doing performance profiling. - # For most programs usage of prealloc will be a premature optimization. - # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them. - # True by default. - simple: true - range-loops: true # Report preallocation suggestions on range loops, true by default - for-loops: true # Report preallocation suggestions on for loops, false by default - unparam: - # Inspect exported functions, default is false. Set to true if no external program/library imports your code. - # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors: - # if it's called for subdir of a project it can't find external interfaces. All text editor integrations - # with golangci-lint call it on a directory with the changed file. - check-exported: false - gci: - # Section configuration to compare against. - # Section names are case-insensitive and may contain parameters in (). - # The default order of sections is 'standard > default > custom > blank > dot', - # If 'custom-order' is 'true', it follows the order of 'sections' option. - # Default: ["standard", "default"] - #sections: - #- standard # Standard section: captures all standard packages. - #- default # Default section: contains all imports that could not be matched to another section type. - #- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled. - #- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled. - # Skip generated files. - # Default: true - skip-generated: true - # Enable custom order of sections. - # If 'true', make the section order the same as the order of 'sections'. - # Default: false - custom-order: false - gosec: - # To select a subset of rules to run. - # Available rules: https://github.com/securego/gosec#available-rules - # Default: [] - means include all rules - includes: - - G101 # Look for hard coded credentials - - G102 # Bind to all interfaces - - G103 # Audit the use of unsafe block - - G104 # Audit errors not checked - - G106 # Audit the use of ssh.InsecureIgnoreHostKey - - G107 # Url provided to HTTP request as taint input - - G108 # Profiling endpoint automatically exposed on /debug/pprof - - G109 # Potential Integer overflow made by strconv.Atoi result conversion to int16/32 - - G110 # Potential DoS vulnerability via decompression bomb - - G111 # Potential directory traversal - - G112 # Potential slowloris attack - - G113 # Usage of Rat.SetString in math/big with an overflow (CVE-2022-23772) - - G114 # Use of net/http serve function that has no support for setting timeouts - - G201 # SQL query construction using format string - - G202 # SQL query construction using string concatenation - - G203 # Use of unescaped data in HTML templates - - G204 # Audit use of command execution - - G301 # Poor file permissions used when creating a directory - - G302 # Poor file permissions used with chmod - - G303 # Creating tempfile using a predictable path - - G304 # File path provided as taint input - - G305 # File traversal when extracting zip/tar archive - - G306 # Poor file permissions used when writing to a new file - - G307 # Deferring a method which returns an error - - G401 # Detect the usage of DES, RC4, MD5 or SHA1 - - G402 # Look for bad TLS connection settings - - G403 # Ensure minimum RSA key length of 2048 bits - - G404 # Insecure random number source (rand) - - G501 # Import blocklist: crypto/md5 - - G502 # Import blocklist: crypto/des - - G503 # Import blocklist: crypto/rc4 - - G504 # Import blocklist: net/http/cgi - - G505 # Import blocklist: crypto/sha1 - - G601 # Implicit memory aliasing of items from a range statement - # To specify a set of rules to explicitly exclude. - # Available rules: https://github.com/securego/gosec#available-rules - # Default: [] - excludes: - - G101 # Look for hard coded credentials - - G102 # Bind to all interfaces - - G103 # Audit the use of unsafe block - - G104 # Audit errors not checked - - G106 # Audit the use of ssh.InsecureIgnoreHostKey - - G107 # Url provided to HTTP request as taint input - - G108 # Profiling endpoint automatically exposed on /debug/pprof - - G109 # Potential Integer overflow made by strconv.Atoi result conversion to int16/32 - - G110 # Potential DoS vulnerability via decompression bomb - - G111 # Potential directory traversal - - G112 # Potential slowloris attack - - G113 # Usage of Rat.SetString in math/big with an overflow (CVE-2022-23772) - - G114 # Use of net/http serve function that has no support for setting timeouts - - G201 # SQL query construction using format string - - G202 # SQL query construction using string concatenation - - G203 # Use of unescaped data in HTML templates - - G204 # Audit use of command execution - - G301 # Poor file permissions used when creating a directory - - G302 # Poor file permissions used with chmod - - G303 # Creating tempfile using a predictable path - - G304 # File path provided as taint input - - G305 # File traversal when extracting zip/tar archive - - G306 # Poor file permissions used when writing to a new file - - G307 # Deferring a method which returns an error - - G401 # Detect the usage of DES, RC4, MD5 or SHA1 - - G402 # Look for bad TLS connection settings - - G403 # Ensure minimum RSA key length of 2048 bits - - G404 # Insecure random number source (rand) - - G501 # Import blocklist: crypto/md5 - - G502 # Import blocklist: crypto/des - - G503 # Import blocklist: crypto/rc4 - - G504 # Import blocklist: net/http/cgi - - G505 # Import blocklist: crypto/sha1 - - G601 # Implicit memory aliasing of items from a range statement - # Exclude generated files - # Default: false - exclude-generated: true - # Filter out the issues with a lower severity than the given value. - # Valid options are: low, medium, high. - # Default: low - severity: medium - # Filter out the issues with a lower confidence than the given value. - # Valid options are: low, medium, high. - # Default: low - confidence: medium - # Concurrency value. - # Default: the number of logical CPUs usable by the current process. - concurrency: 12 - # To specify the configuration of rules. - config: - # Globals are applicable to all rules. - global: - # If true, ignore #nosec in comments (and an alternative as well). - # Default: false - nosec: true - # Add an alternative comment prefix to #nosec (both will work at the same time). - # Default: "" - "#nosec": "#my-custom-nosec" - # Define whether nosec issues are counted as finding or not. - # Default: false - show-ignored: true - # Audit mode enables addition checks that for normal code analysis might be too nosy. - # Default: false - audit: true - G101: - # Regexp pattern for variables and constants to find. - # Default: "(?i)passwd|pass|password|pwd|secret|token|pw|apiKey|bearer|cred" - pattern: "(?i)example" - # If true, complain about all cases (even with low entropy). - # Default: false - ignore_entropy: false - # Maximum allowed entropy of the string. - # Default: "80.0" - entropy_threshold: "80.0" - # Maximum allowed value of entropy/string length. - # Is taken into account if entropy >= entropy_threshold/2. - # Default: "3.0" - per_char_threshold: "3.0" - # Calculate entropy for first N chars of the string. - # Default: "16" - truncate: "32" - # Additional functions to ignore while checking unhandled errors. - # Following functions always ignored: - # bytes.Buffer: - # - Write - # - WriteByte - # - WriteRune - # - WriteString - # fmt: - # - Print - # - Printf - # - Println - # - Fprint - # - Fprintf - # - Fprintln - # strings.Builder: - # - Write - # - WriteByte - # - WriteRune - # - WriteString - # io.PipeWriter: - # - CloseWithError - # hash.Hash: - # - Write - # os: - # - Unsetenv - # Default: {} - G104: - fmt: - - Fscanf - G111: - # Regexp pattern to find potential directory traversal. - # Default: "http\\.Dir\\(\"\\/\"\\)|http\\.Dir\\('\\/'\\)" - pattern: "custom\\.Dir\\(\\)" - # Maximum allowed permissions mode for os.Mkdir and os.MkdirAll - # Default: "0750" - G301: "0750" - # Maximum allowed permissions mode for os.OpenFile and os.Chmod - # Default: "0600" - G302: "0600" - # Maximum allowed permissions mode for os.WriteFile and ioutil.WriteFile - # Default: "0600" - G306: "0600" - - lll: - # Max line length, lines longer will be reported. - # '\t' is counted as 1 character by default, and can be changed with the tab-width option. - # Default: 120. - line-length: 120 - # Tab width in spaces. - # Default: 1 - tab-width: 1 + - gofmt + - goimports linters: - disable-all: true + settings: + staticcheck: + checks: + - all + - -S1023 + - -ST1000 + - -ST1003 + - -ST1020 + gosec: + excludes: + - G104 + - G115 + - G301 + - G304 + - G306 + - G501 + - G505 + exclusions: + paths: + - vendors/ + default: none enable: - govet - - gofmt - errcheck - misspell - gocyclo - ineffassign - - goimports - - nakedret - unparam - unused - prealloc - durationcheck -# - nolintlint - staticcheck - makezero - nilerr - errorlint - bodyclose - - exportloopref - - gci - gosec - - lll - fast: false diff --git a/.lic.yaml b/.lic.yaml index 2387d32..737072f 100644 --- a/.lic.yaml +++ b/.lic.yaml @@ -1,3 +1,3 @@ -author: Mikhail Knyazhev +author: Mikhail Knyazhev lic_short: "BSD 3-Clause" lic_file: LICENSE diff --git a/LICENSE b/LICENSE index da2fb54..2a1ad25 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2024, Mikhail Knyazhev +Copyright (c) 2024-2025, Mikhail Knyazhev Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index f3d697c..25d1f89 --- a/Makefile +++ b/Makefile @@ -1,31 +1,29 @@ +SHELL=/bin/bash .PHONY: install install: - go install github.com/osspkg/devtool@latest - -.PHONY: setup -setup: - devtool setup-lib + go install go.osspkg.com/goppy/v2/cmd/goppy@latest + goppy setup-lib .PHONY: lint lint: - devtool lint + goppy lint .PHONY: license license: - devtool license + goppy license .PHONY: build build: - devtool build --arch=amd64 + goppy build --arch=amd64 .PHONY: tests tests: - devtool test + goppy test .PHONY: pre-commit -pre-commit: setup lint build tests +pre-commit: install license lint tests build .PHONY: ci -ci: install setup lint build tests +ci: pre-commit diff --git a/application.go b/application.go index eb998d3..186d264 100644 --- a/application.go +++ b/application.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2024-2025 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. */ @@ -9,13 +9,14 @@ import ( "go.osspkg.com/config" "go.osspkg.com/console" "go.osspkg.com/events" + "go.osspkg.com/logx" + "go.osspkg.com/xc" + config2 "go.osspkg.com/grape/config" "go.osspkg.com/grape/container" "go.osspkg.com/grape/env" "go.osspkg.com/grape/internal" "go.osspkg.com/grape/reflect" - "go.osspkg.com/logx" - "go.osspkg.com/xc" ) type AppName string @@ -115,9 +116,7 @@ func (a *_grape) ConfigModels(configs ...interface{}) Grape { // ConfigResolvers set configs resolvers func (a *_grape) ConfigResolvers(crs ...config.Resolver) Grape { - for _, r := range crs { - a.resolvers = append(a.resolvers, r) - } + a.resolvers = append(a.resolvers, crs...) return a } diff --git a/application_test.go b/application_test.go index 72b5fba..a8b58cc 100644 --- a/application_test.go +++ b/application_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2024-2025 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. */ @@ -39,9 +39,10 @@ func TestUnit_AppInvoke(t *testing.T) { s.Do(&out) out += "Done" } - grape.New("testapp").Modules( - &Struct1{}, &Struct2{}, - ).Invoke(call1) + grape.New("testapp"). + ConfigData(`env: dev`, `.yaml`). + Modules(&Struct1{}, &Struct2{}). + Invoke(call1) casecheck.Equal(t, "[Struct1.Do]Done", out) out = "" @@ -49,12 +50,14 @@ func TestUnit_AppInvoke(t *testing.T) { s.Do2(&out) out += "Done" } - grape.New("testapp").ExitFunc(func(code int) { - t.Log("Exit Code", code) - casecheck.Equal(t, 0, code) - }).Modules( - NewStruct1, &Struct2{}, - ).Invoke(call1) + grape.New("testapp"). + ConfigData(`env: dev`, `.yaml`). + ExitFunc(func(code int) { + t.Log("Exit Code", code) + casecheck.Equal(t, 0, code) + }). + Modules(NewStruct1, &Struct2{}). + Invoke(call1) casecheck.Equal(t, "[Struct1.Do][Struct2.Do]Done", out) } diff --git a/config/config.go b/config/config.go index e901c3b..8a528d9 100644 --- a/config/config.go +++ b/config/config.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2024-2025 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. */ diff --git a/container/container.go b/container/container.go index 4a112c1..a12a6fd 100644 --- a/container/container.go +++ b/container/container.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2024-2025 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. */ @@ -11,11 +11,12 @@ import ( "go.osspkg.com/algorithms/graph/kahn" "go.osspkg.com/errors" + "go.osspkg.com/syncing" + "go.osspkg.com/xc" + "go.osspkg.com/grape/errs" reflect2 "go.osspkg.com/grape/reflect" "go.osspkg.com/grape/services" - "go.osspkg.com/syncing" - "go.osspkg.com/xc" ) type ( @@ -229,7 +230,7 @@ func (v *_container) callArgs(obj interface{}) (*objectStorageItem, []reflect.Va return item, []reflect.Value{reflect.ValueOf(item.Value)}, nil } -// nolint: gocyclo +//nolint:gocyclo func (v *_container) run() error { names := make(map[string]struct{}) for _, name := range v.kahn.Result() { diff --git a/container/container_test.go b/container/container_test.go index a47dfd0..79c1e53 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2024-2025 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. */ @@ -12,8 +12,9 @@ import ( "go.osspkg.com/casecheck" "go.osspkg.com/errors" - "go.osspkg.com/grape/container" "go.osspkg.com/xc" + + "go.osspkg.com/grape/container" ) func TestUnit_EmptyDI(t *testing.T) { @@ -77,14 +78,14 @@ type SimpleDI1_Service struct { func (v *SimpleDI1_Service) Up() error { if len(v.ErrUp) > 0 { - return fmt.Errorf(v.ErrUp) // nolint: govet + return errors.New(v.ErrUp) //nolint:govet } return nil } func (v *SimpleDI1_Service) Down() error { if len(v.ErrDown) > 0 { - return fmt.Errorf(v.ErrDown) // nolint: govet + return errors.New(v.ErrDown) //nolint:govet } return nil } @@ -351,7 +352,7 @@ func TestUnit_DI_Default(t *testing.T) { &SimpleDI1_A{A: "123"}, SimpleDI1_Struct{}, func(s SimpleDI1_Struct) error { - return fmt.Errorf(s.AA.A) // nolint: govet + return errors.New(s.AA.A) //nolint:govet }, }, wantErr: true, @@ -362,9 +363,9 @@ func TestUnit_DI_Default(t *testing.T) { register: []interface{}{ SimpleString("QWERT"), func(s SimpleString) error { - // nolint: govet - // nolint: staticcheck - return fmt.Errorf(string(s)) + //nolint:govet + //nolint:staticcheck + return errors.New(string(s)) }, }, wantErr: true, diff --git a/container/storage.go b/container/storage.go index 3d7b3e5..cb13bac 100644 --- a/container/storage.go +++ b/container/storage.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2024-2025 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. */ diff --git a/env/envs.go b/env/envs.go index a52c7ab..25f6ddf 100644 --- a/env/envs.go +++ b/env/envs.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2024-2025 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. */ diff --git a/errs/errors.go b/errs/errors.go index af2b523..c620b71 100644 --- a/errs/errors.go +++ b/errs/errors.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2024-2025 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. */ diff --git a/go.mod b/go.mod index 98a54ba..85959d1 100644 --- a/go.mod +++ b/go.mod @@ -1,22 +1,23 @@ module go.osspkg.com/grape -go 1.21 +go 1.24.4 require ( - go.osspkg.com/algorithms v1.4.1 + go.osspkg.com/algorithms v1.6.0 go.osspkg.com/casecheck v0.3.0 - go.osspkg.com/config v0.1.3 + go.osspkg.com/config v0.2.0 go.osspkg.com/console v0.3.3 go.osspkg.com/errors v0.3.1 go.osspkg.com/events v0.3.0 - go.osspkg.com/logx v0.4.2 - go.osspkg.com/syncing v0.3.0 - go.osspkg.com/xc v0.3.1 + go.osspkg.com/logx v0.6.0 + go.osspkg.com/syncing v0.4.0 + go.osspkg.com/xc v0.4.0 ) require ( + github.com/BurntSushi/toml v1.5.0 // indirect github.com/josharian/intern v1.0.0 // indirect - github.com/mailru/easyjson v0.7.7 // indirect - go.osspkg.com/ioutils v0.4.7 // indirect + github.com/mailru/easyjson v0.9.1 // indirect + go.osspkg.com/ioutils v0.7.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 451a52f..f4e1a0b 100644 --- a/go.sum +++ b/go.sum @@ -1,27 +1,29 @@ +github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= +github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= -github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= -github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -go.osspkg.com/algorithms v1.4.1 h1:yCXiNHu+MGiUYU7wFsCg2Q0drLPnu1q13cIrPAHDlXU= -go.osspkg.com/algorithms v1.4.1/go.mod h1:JarWCfCmgxBkk2tA/ABeHScK9WN8azu+bEc27+dF/Gw= +github.com/mailru/easyjson v0.9.1 h1:LbtsOm5WAswyWbvTEOqhypdPeZzHavpZx96/n553mR8= +github.com/mailru/easyjson v0.9.1/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU= +go.osspkg.com/algorithms v1.6.0 h1:8WBXOAW/BE3olXKq4AaaRaD60BoCv1apk4EyoKyeFxM= +go.osspkg.com/algorithms v1.6.0/go.mod h1:Dm8yePWdcvzIdPGDQTuusNpCin8kMGMLaGOAQ62GREc= go.osspkg.com/casecheck v0.3.0 h1:x15blEszElbrHrEH5H02JIIhGIg/lGZzIt1kQlD3pwM= go.osspkg.com/casecheck v0.3.0/go.mod h1:TRFXDMFJEOtnlp3ET2Hix3osbxwPWhvaiT/HfD3+gBA= -go.osspkg.com/config v0.1.3 h1:LAgTTYFzoIf4VNBIpFtjG81rR0/3SG29r+1D8I/YBzs= -go.osspkg.com/config v0.1.3/go.mod h1:MyqvXDgpHLZlO2SM/rqf1zogpUZiXvkZlc/Z+0L7alA= +go.osspkg.com/config v0.2.0 h1:nPf14TX+HnVgOtlX1vobeTl//bQ3T/fAhXASaDRZ5rI= +go.osspkg.com/config v0.2.0/go.mod h1:lYvJ3OfeWIQLr9ToRcDU+7fVCJLirDtKFpdxtAR8K1A= go.osspkg.com/console v0.3.3 h1:UB/pPoPsgWbyNFix8pEMQHbsXdMv/UK/dgsbRknCH2A= go.osspkg.com/console v0.3.3/go.mod h1:IknBCliH6mX/ogHa6wbycnGDFYixCGH3WuNc5W5tQe8= go.osspkg.com/errors v0.3.1 h1:F9m/EEd/Ot2jba/TV7tvVRIpWXzIpNLc7vRJKcBD86A= go.osspkg.com/errors v0.3.1/go.mod h1:dKXe6Rt07nzY7OyKQNZ8HGBicZ2uQ5TKEoVFnVFOK44= go.osspkg.com/events v0.3.0 h1:W2IngTsKs0BKYIglqhrETwtpo6uNSZXWRIt0/l7c6dY= go.osspkg.com/events v0.3.0/go.mod h1:Cjpx+qNM1y2MIAygFyZWYagTuRiYirmKppZQdaZumd4= -go.osspkg.com/ioutils v0.4.7 h1:ERr37BhApkVH34Ebq2yPY+50p38bElSns6pX64wVsyw= -go.osspkg.com/ioutils v0.4.7/go.mod h1:58HhG2NHf9JUtixAH3R2XISlUmJruwVIUZ3039QVjOY= -go.osspkg.com/logx v0.4.2 h1:3kqG7EaaT/DxpHytQm4MfcrmDhYf8ha9/iRpVjpRt88= -go.osspkg.com/logx v0.4.2/go.mod h1:mGbH9hdkeC0h9Gw1uWgQfi9MmlANcqNLffB0wxIDpsQ= -go.osspkg.com/syncing v0.3.0 h1:yBkCsDPEt12a+qagInFFt7+ZongfT+GjSQl7nBmcybI= -go.osspkg.com/syncing v0.3.0/go.mod h1:Dpe0ljlEG6cI2Y9PxEjKiYEX2sgs1eUjWNVjFu4/iB0= -go.osspkg.com/xc v0.3.1 h1:6De75eXdP9CVXqgQOcCWLPyAqFw9zP5lM6rV9MLGiCE= -go.osspkg.com/xc v0.3.1/go.mod h1:6dUG4Y/Q2NMhc5vYrNy0ehWIaHQtAi+MFfc22onQHEs= +go.osspkg.com/ioutils v0.7.1 h1:WDZy6IC2X6jaEN8BAjOo5XyWNL8ZjOxWuBFsh6PWzMs= +go.osspkg.com/ioutils v0.7.1/go.mod h1:aWpiOxKyM6TNs3USc7X29nbv8E7Ibat/+Mtp5RRibRI= +go.osspkg.com/logx v0.6.0 h1:2eP/NaEyJ8QAgzkk29b9klxkaMWaXiIycphdm/hk9jA= +go.osspkg.com/logx v0.6.0/go.mod h1:/Qc1ykuB9V+VZjZkRdu2bVPDrRlixyePriiIy08vAMU= +go.osspkg.com/syncing v0.4.0 h1:9ytMfGHd6Ew69D2n/1syj0FTujNfb1KBiUSZ+KsMTqk= +go.osspkg.com/syncing v0.4.0/go.mod h1:/LBmgCAHFW6nQgVDILpEuo6eRCFK1yyFeNbDs4eVNls= +go.osspkg.com/xc v0.4.0 h1:MGntRGa3EPCpfrTbWEN7x475BAsAtRYGpYEYJ5mE0I8= +go.osspkg.com/xc v0.4.0/go.mod h1:HWDrUQOKMkQser1teXqnFNMB1WVD0YsyIuM1vIKny7U= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/internal/utils.go b/internal/utils.go index f0a95ac..fb4f3f5 100644 --- a/internal/utils.go +++ b/internal/utils.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2024-2025 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. */ diff --git a/logger.go b/logger.go index 9d9837d..03fa950 100644 --- a/logger.go +++ b/logger.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2024-2025 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. */ @@ -13,8 +13,9 @@ import ( "sync" "go.osspkg.com/console" - "go.osspkg.com/grape/config" "go.osspkg.com/logx" + + "go.osspkg.com/grape/config" ) var ( @@ -45,23 +46,17 @@ func initGlobalLogger(tag string, conf config.LogConfig, handler logx.Logger) *_ switch conf.Format { case "syslog": - defer func() { - if p := recover(); p != nil { - console.Fatalf("logger panic [type=%s filepath=%s]: %v", conf.Format, conf.FilePath, p) - } - }() network, addr := "", "" if uri, err0 := url.Parse(conf.FilePath); err0 == nil { network, addr = uri.Scheme, uri.Host } instance.file, err = syslog.Dial(network, addr, syslog.LOG_INFO, tag) default: - instance.file, err = os.OpenFile(conf.FilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) - } - if err != nil { - panic(err) + instance.file, err = os.OpenFile(conf.FilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600) } + console.FatalIfErr(err, "open log file: %s %s", conf.Format, conf.FilePath) + instance.handler.SetOutput(instance.file) instance.handler.SetLevel(instance.conf.Level) diff --git a/modules.go b/modules.go index 6a500f0..a94e7ab 100644 --- a/modules.go +++ b/modules.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2024-2025 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. */ diff --git a/modules_test.go b/modules_test.go index 0febde9..bc69d7a 100644 --- a/modules_test.go +++ b/modules_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2024-2025 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. */ @@ -9,6 +9,7 @@ import ( "testing" "go.osspkg.com/casecheck" + "go.osspkg.com/grape" ) diff --git a/reflect/reflect.go b/reflect/reflect.go index 387ef4e..2217bda 100644 --- a/reflect/reflect.go +++ b/reflect/reflect.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2024-2025 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. */ @@ -15,12 +15,14 @@ const ErrorName = "error" var errType = reflect.TypeOf(new(error)).Elem() -// nolint: gocyclo +//nolint:gocyclo func GetAddress(t reflect.Type, v interface{}) (string, bool) { if t == nil { return "nil", false } + switch t.Kind() { + case reflect.Func: if len(t.PkgPath()) > 0 { return reflectAddressElem(t), true @@ -30,6 +32,7 @@ func GetAddress(t reflect.Type, v interface{}) (string, bool) { } p := reflect.ValueOf(v).Pointer() return fmt.Sprintf("0x%x.%s", p, t.String()), true + case reflect.Ptr: if t.Implements(errType) { return ErrorName, false @@ -39,16 +42,19 @@ func GetAddress(t reflect.Type, v interface{}) (string, bool) { return "*struct{}", false } return value, true + case reflect.Map: key := reflectAddressElem(t.Key()) value := reflectAddressElem(t.Elem()) return fmt.Sprintf("map[%s]%s", key, value), isNotSimple(key) && isNotSimple(value) + case reflect.Struct: value := reflectAddressElem(t) if len(value) == 0 { return "struct{}", false } return value, true + case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, @@ -58,17 +64,22 @@ func GetAddress(t reflect.Type, v interface{}) (string, bool) { reflect.Interface: value := reflectAddressElem(t) return value, isNotSimple(value) + case reflect.Chan: value, _ := GetAddress(t.Elem(), v) return fmt.Sprintf("chan %s", value), isNotSimple(value) + case reflect.Slice: value := reflectAddressElem(t.Elem()) return fmt.Sprintf("[]%s", value), isNotSimple(value) + case reflect.Array: value := reflectAddressElem(t.Elem()) return fmt.Sprintf("[%d]%s", t.Len(), value), isNotSimple(value) + + default: + return t.String(), false } - return t.String(), false } func TypingPtr(vv []interface{}, call func(interface{}) error) ([]interface{}, error) { diff --git a/reflect/reflect_test.go b/reflect/reflect_test.go index 6c1e90a..a402314 100644 --- a/reflect/reflect_test.go +++ b/reflect/reflect_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2024-2025 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. */ @@ -15,7 +15,7 @@ import ( "go.osspkg.com/casecheck" ) -// nolint: lll +//nolint:lll func TestUnit_getReflectAddress2(t *testing.T) { type ( aa string diff --git a/services/services.go b/services/services.go index 0d74ad6..ba5d894 100644 --- a/services/services.go +++ b/services/services.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2024-2025 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. */ @@ -9,9 +9,10 @@ import ( "context" "go.osspkg.com/errors" - "go.osspkg.com/grape/errs" "go.osspkg.com/syncing" "go.osspkg.com/xc" + + "go.osspkg.com/grape/errs" ) type ( @@ -121,13 +122,9 @@ func (s *_services) IterateOver() { for s.tree.Previous != nil { s.tree = s.tree.Previous } - for { - if s.tree.Next == nil { - break - } + for s.tree.Next != nil { s.tree = s.tree.Next } - return } // AddAndUp - add new service and call up