blog
Table des matières
- 2026:
- 2025:
12 billet(s) pour novembre 2026
| Notes conversion JSON YAML | 2026/11/13 11:16 | Jean-Baptiste |
| Git commit perdu | 2026/11/12 18:16 | Jean-Baptiste |
| Notes mojo lang | 2026/11/11 20:34 | Jean-Baptiste |
| Notes rust lang compilation | 2026/11/11 18:35 | Jean-Baptiste |
| Mémoire VSIZE VMSIZE SEGV lang C | 2026/11/11 15:59 | Jean-Baptiste |
| Ansible-navigator utilisation de ansible-vault | 2026/11/06 11:33 | Jean-Baptiste |
| Err Ansible - Module result deserialization failed No start of json char found | 2026/11/06 09:09 | Jean-Baptiste |
| Script Python conversion JSON vers CSV | 2026/11/06 08:14 | Jean-Baptiste |
| Filter Incoming IPv4 Packets Containing IP Options - cve-2026-98432 mitigation - Kernel TCP Use-After-Free | 2026/11/04 21:04 | Jean-Baptiste |
| Notes ZFS | 2026/11/03 18:04 | Jean-Baptiste |
| Diff image container | 2026/11/03 16:30 | Jean-Baptiste |
| Notes processus multi-thread | 2026/11/03 10:59 | Jean-Baptiste |
Création image conteneur - exemple de multi-stage builds
Voir :
Containerfile
FROM golang:latest as builder WORKDIR /build COPY ./build/main.go ./ # RUN go mod download ENV CGO_ENABLED 0 ENV GOOS linux #RUN CGO_ENABLED=0 go build main.go RUN go build -ldflags="-s -w" main.go FROM scratch WORKDIR /app COPY --from=builder /build/main ./main EXPOSE 8080 ENTRYPOINT ["./main"]
build/main.go
package main import ( "fmt" "net/http" ) func homeHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello World ! \n") } func main() { http.HandleFunc("/", homeHandler) http.ListenAndServe(":8080", nil) }
Exécuter du code python avec go lang
Voir :
Voir aussi :
Pb 1
$ go build py.go
# command-line-arguments
./py.go:3:11: fatal error: Python.h: No such file or directory
3 | // #include <Python.h>
| ^~~~~~
Solution
export C_INCLUDE_PATH=/usr/include/python3.13/
Pb 2
$ LANG=C go build py.go # command-line-arguments /usr/lib/go-1.26/pkg/tool/linux_amd64/link: running x86_64-linux-gnu-gcc failed: exit status 1 /usr/bin/x86_64-linux-gnu-gcc -m64 -Wl,--build-id=0x93e927a0e727ab54037ec0b3c85116f34e35a1b2 -o $WORK/b001/exe/a.out -Wl,--export-dynamic-symbol=_cgo_panic -Wl,--export-dynamic-symbol=_cgo_topofstack -Wl,--export-dynamic-symbol=crosscall2 -Wl,--compress-debug-sections=zlib /tmp/go-link-256395171/go.o /tmp/go-link-256395171/000000.o /tmp/go-link-256395171/000001.o /tmp/go-link-256395171/000002.o /tmp/go-link-256395171/000003.o /tmp/go-link-256395171/000004.o /tmp/go-link-256395171/000005.o /tmp/go-link-256395171/000006.o /tmp/go-link-256395171/000007.o /tmp/go-link-256395171/000008.o /tmp/go-link-256395171/000009.o /tmp/go-link-256395171/000010.o /tmp/go-link-256395171/000011.o /tmp/go-link-256395171/000012.o /tmp/go-link-256395171/000013.o /tmp/go-link-256395171/000014.o /tmp/go-link-256395171/000015.o /tmp/go-link-256395171/000016.o -O2 -g -O2 -g -lpthread -no-pie /usr/bin/x86_64-linux-gnu-ld.bfd: /tmp/go-link-256395171/000001.o: in function `_cgo_0270074b3d42_Cfunc_PyRun_SimpleString': /tmp/go-build/cgo-gcc-prolog:55:(.text+0x15): undefined reference to `PyRun_SimpleStringFlags' /usr/bin/x86_64-linux-gnu-ld.bfd: /tmp/go-link-256395171/000001.o: in function `_cgo_0270074b3d42_Cfunc_Py_Finalize': /tmp/go-build/cgo-gcc-prolog:67:(.text+0x31): undefined reference to `Py_Finalize' /usr/bin/x86_64-linux-gnu-ld.bfd: /tmp/go-link-256395171/000001.o: in function `_cgo_0270074b3d42_Cfunc_Py_Initialize': /tmp/go-build/cgo-gcc-prolog:76:(.text+0x41): undefined reference to `Py_Initialize' collect2: error: ld returned 1 exit status
Inclure des appels à Go lang dans Python
Voir :
Voir aussi :
Tuto 1
Source : https://dev.to/leapcell/how-to-call-go-code-in-python-accelerate-python-with-go-54if
Linux and Mac
go build -buildmode=c-shared -o add.so add.go
windows
go build -buildmode=c-shared -o add.dll add.go
go build -ldflags "-s -w" -buildmode=c-shared -o add.so add.go
-s indicates compression -w indicates removing debugging
# Test calling code written in the GO language from Python # First, the GO code needs to be compiled into a dynamic link library from ctypes import cdll lib = cdll.LoadLibrary("./add.so") # Specify the compiled dynamic link library file here # Call the Add function in the GO language result = lib.Add(100, 200) print("result ", result) # Call the PrintDll function in the GO language lib.PrintDll()
Tuto 2
Exemple 1
library.go
package main import ( "C" "log" ) //export helloWorld func helloWorld(){ log.Println("Hello World") } func main(){ }
Compilation de la lib
go build -buildmode=c-shared -o library.so library.go
Execution depuis Python
import ctypes library = ctypes.cdll.LoadLibrary('./library.so') hello_world = library.helloWorld hello_world()
Exemple 2
library.go
//export hello func hello(namePtr *C.char){ name := C.GoString(namePtr) log.Println("Hello", name) }
app.py
hello = library.hello hello.argtypes = [ctypes.c_char_p] hello("everyone".encode('utf-8'))
library.go
//export farewell func farewell() *C.char{ return C.CString("Bye!") }
Notes protocoles TCP/IP - IGMP et multicast
Voir multicast :
Voir IGMP :
iptables règles multicast :
Multicast IGMP (Internet Group Management Protocol) :
- 224.0.0.0/4
Filtre Wireshark pour IGMP et mulicast :
igmp or ip.addr==224.0.0.0/4
Règle iptables pour autoriser IGMP
iptables -I INPUT -p igmp -j ACCEPT iptables -I FORWARD -p igmp -j ACCEPT
Règle pour bloquer le multicast
iptables -A INPUT -m pkttype --pkt-type multicast -j DROP
iptables -A INPUT -m pkttype --pkt-type multicast -j ACCEPT iptables -A FORWARD -m pkttype --pkt-type multicast -j ACCEPT iptables -A OUTPUT -m pkttype --pkt-type multicast -j ACCEPT # Or: iptables -A INPUT -s 224.0.0.0/4 -j ACCEPT iptables -A FORWARD -s 224.0.0.0/4 -d 224.0.0.0/4 -j ACCEPT iptables -A OUTPUT -d 224.0.0.0/4 -j ACCEPT
Source : https://gist.github.com/juliojsb/00e3bb086fd4e0472dbe#file-iptables-multicast-sh
Notes go lang programmation fonctionnelle
Voir :
Voir aussi Expr :
Voir aussi :
map
Voir :
package main import "fmt" //type f_ii func(int) int //func MapInt(f f_ii, l []int) [](int) { func MapInt(f func(int) int, l []int) [](int) { ret := []int{} for _, v := range l { ret = append(ret, f(v)) } return (ret) } func carre(i int) int { return i * i } func main() { liste := []int{1, 2, 3} fmt.Println(MapInt(carre, liste)) }
Voir aussi
package main import "fmt" type FuncType func(int) int func square(x int) int { return x * x } var f FuncType = FuncType(square) func main() { fmt.Println(f(5)) }
Autres
func stringInSlice(a string, list []string) bool { for _, b := range list { if b == a { return true } } return false }
blog.txt · Dernière modification : de 127.0.0.1
