1. golangci-lint 1.1 Environment Setup Install golangci-lint
1$ go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest Example batch script for linting all Go modules in a project:
1@if "%DEBUG%"=="" @echo off 2@rem ########################################################################## 3@rem 4@rem Lint all Go modules in backend and frontend folders 5@rem 6@rem ########################################################################## 7 8@rem Set local scope for variables in Windows NT shell 9if "%OS%"=="Windows_NT" setlocal 10 11setlocal enabledelayedexpansion 12 13@REM Get the directory of this script 14set BAT_PATH=%~dp0 15@REM Navigate to the code directory to ensure consistent behavior 16cd /D %BAT_PATH% 17cd .
...
1. proto File 1// Specifies the version of the proto syntax, either 2 or 3 2syntax = "proto3"; 3// Declares the import path for the generated Go code, which is the path used to import the pb.go file in other code 4option go_package = "internal/controller"; 5// Package name 6package controller; 1@if "%DEBUG%"=="" @echo off 2@rem ########################################################################## 3@rem 4@rem Build proto 5@rem 6@rem ########################################################################## 7 8set DIRNAME=%~dp0 9cd /D %DIRNAME% 10cd .
...
internal 之前没注意这个包名的特殊意义,只知道是内部,但是没想到Go直接将这个命名的包设置为模块级私有访问权限,之前项目中proto生成的.pb.g
...
Commonly used fields [Files] Source: "README.TXT"; DestDir: "{app}"; Flags: onlyifdoesntexist onlyifdoesntexist
Only install the file if it doesn’t already exist on the user’s system.
ignoreversion
Don’t compare version info at all; replace existing files regardless of their version number.This flag should only be used on files private to your application, never on shared system files.
内存对齐 概念 内存对齐是指数据在内存中的存储起始地址必须是某个值的整数倍(通常是2、4、8等)。 操作系统访问内存时是按照字长(word)为单位
...
GO编程陷阱和常见错误 完整内容见鸟窝翻译的Go的50度灰:Golang新开发者要注意的陷阱和常见错误,本文仅列出不那么基础的几项。 使用“ni
...
Dig 背景 之前 gRPC 连接时的 target 一直写死在代码里,联调的时候每次都要修改源码再重新编译,个人倾向于写在配置文件里。程序启动时在初始化过程中已经解析了配
...
Lint 环境 安装 golangci-lint 1$ go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest 1@if "%DEBUG%"=="" @echo off 2@rem ########################################################################## 3@rem 4@rem Lint all go mod in backend and frontend folder 5@rem 6@rem ########################################################################## 7 8@rem Set local scope for the variables with windows NT shell 9if "%OS%"=="Windows_NT" setlocal 10 11setlocal enabledelayedexpansion 12 13@REM 本脚本所在目录 14set BAT_PATH=%~dp0 15@REM 进入code,使在任
...
1// findSmallestMissingNumber finds the smallest missing positive integer in the array 2func findSmallestMissingNumber(nums []int) int { 3 n := len(nums) 4 5 // Traverse the array, placing each number in its correct position 6 for i := 0; i < n; i++ { 7 for nums[i] > 0 && nums[i] <= n && nums[nums[i]-1] != nums[i] { 8 nums[i], nums[nums[i]-1] = nums[nums[i]-1], nums[i] 9 } 10 } 11 12 // Traverse the array again to find the first number not in its correct position 13 for i := 0; i < n; i++ { 14 if nums[i] !
...
1// UndistortImage Distortion Correction 2func UndistortImage(imgData []byte, imgSize image.Point, cameraMatrix gocv.Mat, distCoeffs gocv.Mat, newCameraMatrix gocv.Mat) ([]byte, error) { 3 mapx := gocv.NewMatWithSize(imgSize.X, imgSize.Y, gocv.MatTypeCV32F) 4 defer mapx.Close() 5 mapy := gocv.NewMatWithSize(imgSize.X, imgSize.Y, gocv.MatTypeCV32F) 6 defer mapy.Close() 7 r := gocv.Eye(3, 3, gocv.MatTypeCV32F) 8 defer r.Close() 9 10 // Initialize the correction map 11 gocv.InitUndistortRectifyMap(cameraMatrix, distCoeffs, r, newCameraMatrix, imgSize, int(gocv.MatTypeCV32F), mapx, mapy) 12 // Save the corrected image 13 src, err := gocv.
...