diff --git a/implementation/database.go b/implementation/database.go new file mode 100644 index 0000000..28a9a14 --- /dev/null +++ b/implementation/database.go @@ -0,0 +1,18 @@ +package main + +import ( + "code.gitea.io/gitea/models" + "git.jonasfranz.software/JonasFranzDEV/giteaplugin/interfaces" +) + +type UserDatabaseImpl struct {} + +func (*UserDatabaseImpl) CreateUser(user *interfaces.User) error { + return models.CreateUser(&models.User{ + Name: user.Name, + Email: user.Email, + Passwd: user.Passwd, + IsAdmin: user.IsAdmin, + IsActive: user.IsActive, + }) +} diff --git a/implementation/demo.so b/implementation/demo.so new file mode 100644 index 0000000..ae939bc Binary files /dev/null and b/implementation/demo.so differ diff --git a/implementation/main.go b/implementation/main.go new file mode 100644 index 0000000..b2bff09 --- /dev/null +++ b/implementation/main.go @@ -0,0 +1,12 @@ +package main + +import ( + "git.jonasfranz.software/JonasFranzDEV/giteaplugin/interfaces" + "plugin" +) + +func main() { + p, _ := plugin.Open("demo.so") + start, _ := p.Lookup("Start") + start.(func(database interfaces.UserDatabase))(&UserDatabaseImpl{}) +} diff --git a/interfaces/database.go b/interfaces/database.go new file mode 100644 index 0000000..7e962ef --- /dev/null +++ b/interfaces/database.go @@ -0,0 +1,13 @@ +package interfaces + +type User struct { + Name string + Email string + Passwd string + IsAdmin bool + IsActive bool +} + +type UserDatabase interface { + CreateUser(user *User) error +} diff --git a/main.go b/main.go deleted file mode 100644 index 7fa630e..0000000 --- a/main.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -import ( - "code.gitea.io/gitea/models" - "code.gitea.io/gitea/modules/log" -) - -func StartPlugin() { - err := models.CreateUser(&models.User{ - Name: "NicePlugin", - Email: "plugin@knt.li", - Passwd: "test", - IsActive: false, - IsAdmin: false, - }) - if err != nil { - log.Error(4, "StartPlugin: %v", err) - } -} diff --git a/plugin/main.go b/plugin/main.go new file mode 100644 index 0000000..1901b8e --- /dev/null +++ b/plugin/main.go @@ -0,0 +1,7 @@ +package main + +import "git.jonasfranz.software/JonasFranzDEV/giteaplugin/interfaces" + +func Start(database interfaces.UserDatabase) { + _ = database.CreateUser(&interfaces.User{}) +}