fix panic
This commit is contained in:
parent
b2e65a9df0
commit
40d11f97f4
|
@ -18,7 +18,7 @@ func (acc *account) unmarshal(data map[string]interface{}) {
|
||||||
typeOfPerson := valueOfPerson.Type()
|
typeOfPerson := valueOfPerson.Type()
|
||||||
for i := 0; i < valueOfPerson.NumField(); i++ {
|
for i := 0; i < valueOfPerson.NumField(); i++ {
|
||||||
field := valueOfPerson.Field(i)
|
field := valueOfPerson.Field(i)
|
||||||
tag := typeOfPerson.Field(i).Tag.Get("mytag")
|
tag := typeOfPerson.Field(i).Tag.Get("prosody")
|
||||||
|
|
||||||
if val, ok := data[tag]; ok {
|
if val, ok := data[tag]; ok {
|
||||||
field.Set(reflect.ValueOf(val))
|
field.Set(reflect.ValueOf(val))
|
||||||
|
@ -28,7 +28,10 @@ func (acc *account) unmarshal(data map[string]interface{}) {
|
||||||
|
|
||||||
// loadAccount read the user .dat file and retrieves the data store in it
|
// loadAccount read the user .dat file and retrieves the data store in it
|
||||||
func (p *Prosody) loadAccount(username string) (*account, error) {
|
func (p *Prosody) loadAccount(username string) (*account, error) {
|
||||||
var acc *account
|
if strings.HasSuffix(username, p.plainDomain) {
|
||||||
|
username = strings.Replace(username, p.plainDomain, "", -1)
|
||||||
|
}
|
||||||
|
|
||||||
data, err := os.ReadFile(p.accountsPath + username + ".dat")
|
data, err := os.ReadFile(p.accountsPath + username + ".dat")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -45,6 +48,7 @@ func (p *Prosody) loadAccount(username string) (*account, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
acc := &account{}
|
||||||
acc.unmarshal(mapValues)
|
acc.unmarshal(mapValues)
|
||||||
return acc, nil
|
return acc, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,26 @@
|
||||||
package prosody
|
package prosody
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
)
|
||||||
|
|
||||||
type Prosody struct {
|
type Prosody struct {
|
||||||
binPath string
|
binPath string
|
||||||
|
plainDomain string
|
||||||
accountsPath string
|
accountsPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
// /var/lib/prosody/xmpp%%2eurkob%%2ecom/accounts/
|
// /var/lib/prosody/xmpp%%2eurkob%%2ecom/accounts/
|
||||||
func NewProsody(domain string) *Prosody {
|
func NewProsody(domain string) *Prosody {
|
||||||
|
plainDomain, err := url.QueryUnescape(domain)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("urlQueryUnescape %w", err))
|
||||||
|
}
|
||||||
return &Prosody{
|
return &Prosody{
|
||||||
binPath: "/usr/bin/prosodyctl",
|
binPath: "/usr/bin/prosodyctl",
|
||||||
accountsPath: "/var/lib/prosody/" + domain + "/accounts/",
|
accountsPath: "/var/lib/prosody/" + domain + "/accounts/",
|
||||||
|
plainDomain: plainDomain,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue