initial
This commit is contained in:
commit
74ae93a96e
1 changed files with 94691 additions and 0 deletions
50
joplin notion extension/Web Development/Go/extras.md
Normal file
50
joplin notion extension/Web Development/Go/extras.md
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
extras
|
||||
|
||||
- to get type of variable
|
||||
`fmt.Println(reflect.TypeOf(student))`
|
||||
|
||||
- for signals
|
||||
`signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)`
|
||||
- sc — a chan os.Signal (must be buffered, e.g. make(chan os.Signal, 1)) that will receive the signal values.
|
||||
- syscall.SIGINT — interrupt from the keyboard (Ctrl+C).
|
||||
- syscall.SIGTERM — polite termination request (e.g. kill <pid> or what Kubernetes sends on pod shutdown).
|
||||
- os.Interrupt — a platform-agnostic alias; on Unix it's the same as syscall.SIGINT, on Windows it also covers Ctrl+Break.
|
||||
|
||||
|
||||
for deeply mested objects printing in console
|
||||
|
||||
```go
|
||||
data, _ := json.MarshalIndent(m, "", " ")
|
||||
fmt.Printf("detected: %v\n", string(data))
|
||||
```
|
||||
|
||||
|
||||
|
||||
go equivalent to `fs.mkdirSync(dirPath,{recursive: true}`
|
||||
|
||||
this will create directories recurselovely and wont throw error if it exist
|
||||
```go
|
||||
err := os.MkdirAll(dirPath, 0755)
|
||||
```
|
||||
|
||||
creating a build for all platfoms
|
||||
|
||||
script
|
||||
```sh
|
||||
#!/bin/bash
|
||||
# Iterate through all supported GOOS/GOARCH combinations
|
||||
go tool dist list | while read platform; do
|
||||
# Split platform into OS and ARCH
|
||||
GOOS=${platform%/*}
|
||||
GOARCH=${platform#*/}
|
||||
|
||||
# Define output filename
|
||||
output_name="myapp-${GOOS}-${GOARCH}"
|
||||
if [ "$GOOS" = "windows" ]; then
|
||||
output_name+=".exe"
|
||||
fi
|
||||
|
||||
# Build the binary
|
||||
env GOOS=$GOOS GOARCH=$GOARCH go build -o "$output_name" .
|
||||
done
|
||||
```
|
||||
Loading…
Reference in a new issue