Created
April 16, 2018 22:18
-
-
Save BrianLeishman/1720c3c3d47b799d5dd913cedea654c5 to your computer and use it in GitHub Desktop.
MySQL UDF written in Go (Golang) instead of C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// #include <stdio.h> | |
// #include <sys/types.h> | |
// #include <sys/stat.h> | |
// #include <stdlib.h> | |
// #include <string.h> | |
// #include <mysql.h> | |
// #cgo CFLAGS: -D ENVIRONMENT=0 -I/usr/include/mysql -fno-omit-frame-pointer | |
import "C" | |
//export bid2_go_init | |
func bid2_go_init(initid *C.UDF_INIT, args *C.UDF_ARGS, message *C.char) C.my_bool { | |
return 0 | |
} | |
//export bid2_go | |
func bid2_go(initid *C.UDF_INIT, args *C.UDF_ARGS, result *C.char, length *uint64, isNull *C.char, message *C.char) *C.char { | |
*length = 8 | |
return C.CString("yeet fam") | |
} | |
func main() {} |
Many thanks bro!!! Saved my life!!!
Simple and direct... gotcha! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
go build -buildmode=c-shared -o udf.so && cp udf.so /usr/lib/mysql/plugin/udf.so