From 596531ecf5c972f187dba1db40f5f975738ca940 Mon Sep 17 00:00:00 2001 From: PioLing <964472638@qq.com> Date: Wed, 18 Sep 2024 17:36:06 +0800 Subject: [PATCH] Add golang sdk for mk_api (#3914) --- golang/tester/sdk_test.go | 15 ++++++++++ golang/zlmediakit/mk_common.go | 51 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 golang/tester/sdk_test.go create mode 100644 golang/zlmediakit/mk_common.go diff --git a/golang/tester/sdk_test.go b/golang/tester/sdk_test.go new file mode 100644 index 00000000..b03659b6 --- /dev/null +++ b/golang/tester/sdk_test.go @@ -0,0 +1,15 @@ +package tester + +import ( + "testing" + "time" + "zlmediakit/zlmediakit" +) + +func TestServer(t *testing.T) { + zlmediakit.MK_env_init2(0, zlmediakit.LTrace, zlmediakit.LOG_CONSOLE|zlmediakit.LOG_CALLBACK|zlmediakit.LOG_FILE, + "log", 7, true, "../../conf/config.ini", true, "../../default.pem", "") + zlmediakit.MK_http_server_start(80, false) + zlmediakit.MK_http_server_start(443, true) + time.Sleep(1000 * time.Second) +} diff --git a/golang/zlmediakit/mk_common.go b/golang/zlmediakit/mk_common.go new file mode 100644 index 00000000..4e5ff50c --- /dev/null +++ b/golang/zlmediakit/mk_common.go @@ -0,0 +1,51 @@ +package zlmediakit + +/* +#include "mk_mediakit.h" +#cgo CFLAGS: -I../../api/include +#cgo LDFLAGS: -L../../release/linux/Debug/ -lmk_api +*/ +import "C" + +type LOG_MASK int +type LOG_LEVEL int + +const ( + LOG_CONSOLE LOG_MASK = 1 << 0 + LOG_FILE LOG_MASK = 1 << 1 + LOG_CALLBACK LOG_MASK = 2 << 1 +) + +const ( + LTrace LOG_LEVEL = 0 + LDebug LOG_LEVEL = 1 + LInfo LOG_LEVEL = 2 + LWarn LOG_LEVEL = 3 + LError LOG_LEVEL = 4 +) + +func btoi(b bool) int { + if b { + return 1 + } + return 0 +} + +func MK_env_init2(thread_num int, log_level LOG_LEVEL, log_mask LOG_MASK, log_file_path string, log_file_days int, ini_is_path bool, ini string, ssl_is_path bool, ssl string, ssl_pwd string) { + // 调用 C SDK 的函数 + C.mk_env_init2(C.int(thread_num), C.int(log_level), C.int(log_mask), C.CString(log_file_path), C.int(log_file_days), C.int(btoi(ini_is_path)), C.CString(ini), C.int(btoi(ssl_is_path)), C.CString(ssl), C.CString(ssl_pwd)) +} + +func MK_stop_all_server() { + // 调用 C SDK 的函数 + C.mk_stop_all_server() +} + +func MK_set_log(file_max_size, file_max_count int) { + // 调用 C SDK 的函数 + C.mk_set_log(C.int(file_max_size), C.int(file_max_count)) +} + +func MK_http_server_start(port uint16, ssl bool) { + C.mk_http_server_start(C.ushort(port), C.int(btoi(ssl))) +}