github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/experimental/libbox/setup.go (about)

     1  package libbox
     2  
     3  import (
     4  	"os"
     5  	"os/user"
     6  	"strconv"
     7  
     8  	C "github.com/inazumav/sing-box/constant"
     9  
    10  	"github.com/dustin/go-humanize"
    11  )
    12  
    13  var (
    14  	sBasePath    string
    15  	sWorkingPath string
    16  	sTempPath    string
    17  	sUserID      int
    18  	sGroupID     int
    19  	sTVOS        bool
    20  )
    21  
    22  func Setup(basePath string, workingPath string, tempPath string, isTVOS bool) {
    23  	sBasePath = basePath
    24  	sWorkingPath = workingPath
    25  	sTempPath = tempPath
    26  	sUserID = os.Getuid()
    27  	sGroupID = os.Getgid()
    28  	sTVOS = isTVOS
    29  }
    30  
    31  func SetupWithUsername(basePath string, workingPath string, tempPath string, username string) error {
    32  	sBasePath = basePath
    33  	sWorkingPath = workingPath
    34  	sTempPath = tempPath
    35  	sUser, err := user.Lookup(username)
    36  	if err != nil {
    37  		return err
    38  	}
    39  	sUserID, _ = strconv.Atoi(sUser.Uid)
    40  	sGroupID, _ = strconv.Atoi(sUser.Gid)
    41  	return nil
    42  }
    43  
    44  func Version() string {
    45  	return C.Version
    46  }
    47  
    48  func FormatBytes(length int64) string {
    49  	return humanize.IBytes(uint64(length))
    50  }
    51  
    52  func ProxyDisplayType(proxyType string) string {
    53  	return C.ProxyDisplayName(proxyType)
    54  }