Skip to content

被替换的函数中如果包含第三方依赖怎么处理? #1

Description

@hhq163

phantacix,你好:
想要替换的是业务处理的函数,它会有一些第三方的依赖,如:
github.com/golang/protobuf/proto
xxx.com/root/DawnCore/basic //自建的项目公共库,里面包含日志类
。。。
而且还用到一些全局变量,如日志,连接器对象等,xxx.com是公司域名,有点敏感,就用xxx.com代替了

在项目中写一个例子尝试了下,会报错:
[2023-11-09 11:21:00,222][0 0 Error 7 1]hotfixdo.go:19 hotfix.ApplyFunc(),err=./_patch_files/patch/patch.go:8:2: import "xxx.com/root/DawnCore/basic" error: unable to find source related to: "xxx.com/root/DawnCore/basic". Either the GOPATH environment variable, or the Interpreter.Options.GoPath needs to be set

`package patch

import (
"fmt"
"reflect"

"github.com/golang/protobuf/proto"
"xxx.com/root/DawnCore/basic"
"xxx.com/root/DawnFriend/hotfix"
"xxx.com/root/DawnFriend/impl"
"xxx.com/root/DawnMicroHub"
"xxx.com/root/DawnMicroHub/econnector"
"xxx.com/root/DawnMicroHub/proto/csmsg"

)

func GetPatch() *hotfix.FuncPatch {
fmt.Println("invoke GetPatch()")

fn := func(handler *impl.MSG_FRIEND_APPLY_AGREE_ALL_REQ, ec econnector.IExchangeConnector, req *DawnMicroHub.Packet) {
	msg := &csmsg.TMSG_FRIEND_APPLY_AGREE_ALL_REQ{}
	err := proto.Unmarshal(req.Data, msg)
	if err != nil {
		basic.Log.Error("roldId=", req.RoleID, ",err=", err.Error())
		return
	}
	basic.Log.Debug("new func(), roldId=", req.RoleID, ",HandleFriendApplyAgreeAllReq() req msg=", msg.String())

	return
}

return &hotfix.FuncPatch{
	StructType: reflect.TypeOf(&impl.TMSG_FRIEND_APPLY_AGREE_ALL_REQ{}),
	FuncName:   "HandleFriendApplyAgreeAllReq",
	FuncValue:  reflect.ValueOf(fn),
}

}
`
是我的写法不对吗?还是需要把整个xxx.com/root/DawnCore的源码都要放到patch文件夹?这样不太可取,有泄露源代码的风险

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions