Don't use full package path as source identifier

This commit is contained in:
nemunaire 2020-07-18 01:36:20 +02:00
parent 3efa233a7c
commit f2eb1abac0
6 changed files with 11 additions and 7 deletions

View File

@ -84,7 +84,7 @@ func main() {
}
d.Sources = append(d.Sources, srcFile)
d.Map["git.happydns.org/happydns/"+strings.TrimSuffix(srcFile, ".png")] = data
d.Map[strings.Replace(strings.TrimPrefix(strings.TrimSuffix(srcFile, ".png"), "sources/"), "/", ".", -1)] = data
}
f, err := os.Create(dir + "/icons.go")

View File

@ -177,7 +177,7 @@ func (s *DDNSServer) UpdateSOA(domain *happydns.Domain, newSOA *dns.SOA, refresh
}
func init() {
sources.RegisterSource("git.happydns.org/happydns/sources/ddns/DDNSServer", func() happydns.Source {
sources.RegisterSource(func() happydns.Source {
return &DDNSServer{}
}, sources.SourceInfos{
Name: "Dynamic DNS",

View File

@ -34,6 +34,7 @@ package sources // import "happydns.org/sources"
import (
"fmt"
"log"
"reflect"
"git.happydns.org/happydns/model"
)
@ -47,8 +48,11 @@ type Source struct {
var sources map[string]Source = map[string]Source{}
func RegisterSource(name string, creator SourceCreator, infos SourceInfos) {
func RegisterSource(creator SourceCreator, infos SourceInfos) {
baseType := reflect.Indirect(reflect.ValueOf(creator())).Type()
name := baseType.String()
log.Println("Registering new source:", name)
sources[name] = Source{
creator,
infos,

File diff suppressed because one or more lines are too long

View File

@ -306,7 +306,7 @@ func init() {
flag.StringVar(&appKey, "ovh-application-key", "", "Application Key for using the OVH API")
flag.StringVar(&appSecret, "ovh-application-secret", "", "Application Secret for using the OVH API")
sources.RegisterSource("git.happydns.org/happydns/sources/ovh/OVHAPI", func() happydns.Source {
sources.RegisterSource(func() happydns.Source {
return &OVHAPI{}
}, sources.SourceInfos{
Name: "OVH",

View File

@ -133,7 +133,7 @@ func (s *LevelDBStorage) CreateSource(u *happydns.User, src happydns.Source, com
st := &happydns.SourceCombined{
src,
happydns.SourceMeta{
Type: sType.PkgPath() + "/" + sType.Name(),
Type: sType.String(),
Id: id,
OwnerId: u.Id,
Comment: comment,