libXray icon indicating copy to clipboard operation
libXray copied to clipboard

import _ "github.com/xtls/xray-core/main/distro/all"

Open sachako opened this issue 11 months ago • 1 comments

This is not an issue, just want to ask you a question. Can you point me to go docs why this line https://github.com/XTLS/libXray/blob/c1d867b9cb805f75414940a8e0d55e47b7926456/xray/xray.go#L10 is crucial to include transitive dependencies of xray-core in libxray? Why import "github.com/xtls/xray-core/core" is not enough?

sachako avatar Dec 20 '24 19:12 sachako

Sorry, I am not skilful in golang. Other libs also use this line too, like AndroidLibXrayLite.

yiguodev avatar Dec 21 '24 02:12 yiguodev

This is not an issue, just want to ask you a question. Can you point me to go docs why this line

libXray/xray/xray.go

Line 10 in c1d867b

_ "github.com/xtls/xray-core/main/distro/all"

is crucial to include transitive dependencies of xray-core in libxray? Why import "github.com/xtls/xray-core/core" is not enough?

In GoLang it's called Blank Import. When you do this it calls the init() function of the imported package. For example it's similar to other programming languages like java where you create an object of a class and it calls its constructor. The difference is with blank import you are causing the init() function of that package to run not actually creating any instances.

codewithtamim avatar May 21 '25 13:05 codewithtamim