Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

代码规范:user-manager lint #2662

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bcs-services/bcs-user-manager/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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 app xxx
Expand Down Expand Up @@ -47,6 +46,7 @@ func Run(op *options.UserManagerOptions) {
component.CacheClusterList()

if conf.ClientCert.IsSSL {
// nolint
cliTLS, err := ssl.ClientTslConfVerity(conf.ClientCert.CAFile, conf.ClientCert.CertFile, conf.ClientCert.KeyFile,
conf.ClientCert.CertPasswd)
if err != nil {
Expand All @@ -66,7 +66,7 @@ func Run(op *options.UserManagerOptions) {
}

// init cmdb client
if err := cmdb.InitCMDBClient(op); err != nil {
if err = cmdb.InitCMDBClient(op); err != nil {
blog.Errorf("init cmdb client error: %s", err.Error())
os.Exit(1)
}
Expand Down
4 changes: 2 additions & 2 deletions bcs-services/bcs-user-manager/app/pkg/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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 auth xxx
Expand All @@ -21,8 +20,9 @@ import (
"time"

"github.com/Tencent/bk-bcs/bcs-common/common/blog"
"github.com/Tencent/bk-bcs/bcs-services/bcs-user-manager/config"
"github.com/parnurzeal/gorequest"

"github.com/Tencent/bk-bcs/bcs-services/bcs-user-manager/config"
)

// Auth interface for accessToken
Expand Down
1 change: 0 additions & 1 deletion bcs-services/bcs-user-manager/app/pkg/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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 auth
Expand Down
1 change: 0 additions & 1 deletion bcs-services/bcs-user-manager/app/pkg/auth/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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 auth
Expand Down
2 changes: 1 addition & 1 deletion bcs-services/bcs-user-manager/app/pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* 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 cache xxx
package cache

import (
Expand Down
3 changes: 2 additions & 1 deletion bcs-services/bcs-user-manager/app/pkg/component/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* 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 component xxx
package component

import (
Expand Down Expand Up @@ -145,6 +145,7 @@ var defaultTransport http.RoundTripper = &http.Transport{
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
// NOCC:gas/tls(设计如此)
// nolint
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}

Expand Down
5 changes: 2 additions & 3 deletions bcs-services/bcs-user-manager/app/pkg/component/cmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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 component
Expand Down Expand Up @@ -36,10 +35,10 @@ const (
// CacheClusterList 定时同步 cluster 列表
func CacheClusterList() {
go func() {
GetAllCluster()
_, _ = GetAllCluster()
for range time.Tick(time.Minute) {
klog.Infof("list clusters running")
GetAllCluster()
_, _ = GetAllCluster()
klog.Infof("list clusters end")
}
}()
Expand Down
1 change: 0 additions & 1 deletion bcs-services/bcs-user-manager/app/pkg/component/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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 component
Expand Down
3 changes: 2 additions & 1 deletion bcs-services/bcs-user-manager/app/pkg/constant/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* 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 constant xxx
package constant

const (
Expand All @@ -24,6 +24,7 @@ const (
// we can refer to http://coolaf.com/tool/rd when testing
DefaultTokenLength = 32
// TokenKeyPrefix is the redis key for token
// nolint
TokenKeyPrefix = "bcs_auth:token:" // NOCC:gas/crypto(误报)
// TokenLimits for token
TokenLimits = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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 discovery xxx
Expand Down Expand Up @@ -188,6 +187,7 @@ func (sd *ServiceDiscovery) GetRandomServiceInstance() (*registry.Node, error) {
return nil, errors.New("allServiceNodes is empty")
}
// NOCC:gas/crypto(设计如此)
// nolint
selected := rand.Int() % nodeLength
return allServiceNodes[selected], nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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 discovery
Expand Down Expand Up @@ -36,7 +35,7 @@ func NewRegistry() registry.Registry {
registry.Addrs(etcdEndpoints),
registry.Secure(false),
)
etcdRegistry.Init()
_ = etcdRegistry.Init()

return etcdRegistry
}
Expand All @@ -50,6 +49,7 @@ func Test_GetRandomServiceInstance(t *testing.T) {
t.Fatalf("start service discovery failed: %v", err)
}

// nolint
go func() {
for {
<-time.After(3 * time.Second)
Expand All @@ -65,6 +65,7 @@ func Test_GetRandomServiceInstance(t *testing.T) {
signalChan := make(chan os.Signal, 2)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)

// nolint
select {
case <-signalChan:
sd.Stop()
Expand Down
6 changes: 3 additions & 3 deletions bcs-services/bcs-user-manager/app/pkg/encrypt/des.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
* 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 encrypt xxx
package encrypt

import (
"bytes"
"crypto/cipher"

// NOCC:gas/crypto(设计如此)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不需要删除

"crypto/des"
"encoding/base64"
)
Expand All @@ -40,6 +38,7 @@ func PKCS5UnPadding(origData []byte) []byte {
func DesEncryptToBase(src []byte, priKey string) ([]byte, error) {
if len(priKey) != 0 {
// NOCC:gas/crypto(设计如此)
// nolint
block, err := des.NewTripleDESCipher([]byte(priKey))
if err != nil {
return nil, err
Expand All @@ -63,6 +62,7 @@ func DesDecryptFromBase(src []byte, priKey string) ([]byte, error) {
}
var block cipher.Block
// NOCC:gas/crypto(设计如此)
// nolint
block, err = des.NewTripleDESCipher([]byte(priKey))
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion bcs-services/bcs-user-manager/app/pkg/errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* 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 errors xxx
package errors

import "errors"
Expand Down
2 changes: 2 additions & 0 deletions bcs-services/bcs-user-manager/app/pkg/esb/cmdb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
* limitations under the License.
*/

// Package cmdb xxx
package cmdb

import (
"fmt"

"github.com/Tencent/bk-bcs/bcs-common/common/encrypt"
"github.com/Tencent/bk-bcs/bcs-common/pkg/esb/cmdbv3"

"github.com/Tencent/bk-bcs/bcs-services/bcs-user-manager/options"
)

Expand Down
1 change: 1 addition & 0 deletions bcs-services/bcs-user-manager/app/pkg/jwt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package jwt

import (
"github.com/Tencent/bk-bcs/bcs-common/pkg/auth/jwt"

"github.com/Tencent/bk-bcs/bcs-services/bcs-user-manager/options"
)

Expand Down
2 changes: 1 addition & 1 deletion bcs-services/bcs-user-manager/app/pkg/lock/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under,
* 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.
Expand Down
8 changes: 7 additions & 1 deletion bcs-services/bcs-user-manager/app/pkg/lock/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under,
* 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.
Expand All @@ -29,14 +29,20 @@ type Options struct {
}

// LockOptions options for lock
// NOCC:golint/revive(设计如此:)
// nolint
type LockOptions struct {
TTL time.Duration
}

// LockOption option function for lock
// NOCC:golint/revive(设计如此:)
// nolint
type LockOption func(o *LockOptions)

// LockTTL sets the lock ttl
// NOCC:golint/revive(设计如此:)
// nolint
func LockTTL(t time.Duration) LockOption {
return func(o *LockOptions) {
o.TTL = t
Expand Down
2 changes: 1 addition & 1 deletion bcs-services/bcs-user-manager/app/pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* 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 log xxx
package log

import (
Expand Down
2 changes: 1 addition & 1 deletion bcs-services/bcs-user-manager/app/pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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 metrics xxx
Expand Down Expand Up @@ -76,6 +75,7 @@ func RunMetric(conf *config.UserMgrConfig) {
addresses = append(addresses, conf.IPv6Address)
}
metricServer := ipv6server.NewIPv6Server(addresses, strconv.Itoa(int(conf.MetricPort)), "", metricMux)
// nolint
go metricServer.ListenAndServe()

blog.Infof("run metric ok")
Expand Down
4 changes: 2 additions & 2 deletions bcs-services/bcs-user-manager/app/pkg/middleware/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* 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 middleware xxx
package middleware

import (
Expand All @@ -29,7 +29,7 @@ import (
func LoggingFilter(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
inBody, err := io.ReadAll(request.Request.Body)
if err != nil {
response.WriteError(400, err)
_ = response.WriteError(400, err)
return
}
blog.Log(request.Request.Context()).Infof("url: %s, method: %s, request: %s", request.Request.URL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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 middleware
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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 middleware
Expand Down
5 changes: 3 additions & 2 deletions bcs-services/bcs-user-manager/app/pkg/middleware/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* 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 middleware
Expand Down Expand Up @@ -55,6 +54,8 @@ func TracingFilter(request *restful.Request, response *restful.Response, chain *
// get http X-Request-Id
requestID := request.Request.Header.Get(constant.RequestIDHeaderKey)
// 使用requestID当作TraceID
// NOCC:golint/staticcheck(设计如此:)
// nolint
ctx = context.WithValue(ctx, constant.RequestIDKey, requestID)
ctx = traceUtil.ContextWithRequestID(ctx, requestID)
}
Expand Down Expand Up @@ -91,7 +92,7 @@ func TracingFilter(request *restful.Request, response *restful.Response, chain *
}
span.SetAttributes(attribute.Key("query").String(query))

//记录body
// 记录body
body := string(getRequestBody(request.Request))
if len(body) > 1024 {
body = fmt.Sprintf("%s...(Total %s)", body[:1024], humanize.Bytes(uint64(len(body))))
Expand Down
2 changes: 1 addition & 1 deletion bcs-services/bcs-user-manager/app/pkg/parser/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* 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 parser xxx
package parser

import (
Expand Down
Loading
Loading