简体   繁体   中英

Placeholders in import statement in go

I am using the go language and I want to understand the alternative to one scenario that I am facing.

we have import statements in the files as

import "github.com/Dir1/Dir2/v101/ServiceName"

I have a dependency on SDK which follows the directory structure like this. It has version_no directory.

Problem - Every-time the SDK version is updated we have to replace the import statement with appropriate version.

Currently in project it is achieved using the sed command which is very heavy operation as we have thousands of files. Ex Changing "github.com/Dir1/Dir2/v101/ServiceName" ==> "github.com/Dir1/Dir2/v102/ServiceName"

SDK team will not provide any support so we have to find the good way to resolve this.

I need your suggestion about how this can be achieved.

Add this in the go.mod file:

replace github.com/Dir1/Dir2/v101/ServiceName => github.com/Dir1/Dir2/v102/ServiceName

Now, you can keep using github.com/Dir1/Dir2/v101/ServiceName everywhere, and update this replace directive every time the version needs to be updated. For example, if the next version is v103 , update this:

replace github.com/Dir1/Dir2/v101/ServiceName => github.com/Dir1/Dir2/v103/ServiceName

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM