Score:0

Set Gsetting proxy setting in golang

jp flag

I have my golang program running as root service and I am trying to set the proxy setting using the gsettings command in my program. I am able to read these settings in my golang program using the following command code in golang:

u, erru:= user.Lookup("dimdimuser")
if erru != nil {
    return "",fmt.Errorf("unknown user info")
}
uid, err = strconv.ParseInt(u.Uid, 10, 32)
gid, err = strconv.ParseInt(u.Gid, 10, 32)
cmd := exec.Command("/usr/bin/gsettings", "get", "org.gnome.system.proxy", "autoconfig-url") 
cmd.Stdout = &out
cmd.Stderr = &stderr
cmd.SysProcAttr = &syscall.SysProcAttr{}
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
err = cmd.Run()
if err != nil {
    
    return "", fmt.Errorf("Failed '/usr/bin/gsettings' %s %s ", getOrSet, option)
}


return out.String(), nil 

but when I am trying to set these setting the command does not report any error but the setting does not change. here is the code that I am trying to set autoconfig-url:

cmd := exec.Command("/usr/bin/gsettings", "set", "org.gnome.system.proxy", "autoconfig-url","HTTP://localhost/dimdimproxy") 
cmd.Stdout = &out
cmd.Stderr = &stderr
cmd.SysProcAttr = &syscall.SysProcAttr{}
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
err = cmd.Run()
if err != nil {
    
    return "", fmt.Errorf("Failed ")
}

return out.String(), nil 

I have tried using dbus-launch, which changes the setting if I am trying to retrieve from my program or on other terminal tab with local user privilege. but gnome UI does not get reflected. and also system browser also does not accept the changes done by following command.

sudo -Hu dimdim dbus-launch gsettings set org.gnome.system.proxy autoconfig-url htt://localhost/dimdimproxy
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.