Browse Source

Add plugin example

Add implementation example
Add interfaces example
master
Jonas Franz 3 years ago
parent
commit
7fafcdba47
Signed by: JonasFranzDEV
GPG Key ID: 7293A220B7C38080
  1. 18
      implementation/database.go
  2. BIN
      implementation/demo.so
  3. 12
      implementation/main.go
  4. 13
      interfaces/database.go
  5. 19
      main.go
  6. 7
      plugin/main.go

18
implementation/database.go

@ -0,0 +1,18 @@ @@ -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,
})
}

BIN
implementation/demo.so

Binary file not shown.

12
implementation/main.go

@ -0,0 +1,12 @@ @@ -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{})
}

13
interfaces/database.go

@ -0,0 +1,13 @@ @@ -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
}

19
main.go

@ -1,19 +0,0 @@ @@ -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)
}
}

7
plugin/main.go

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
package main
import "git.jonasfranz.software/JonasFranzDEV/giteaplugin/interfaces"
func Start(database interfaces.UserDatabase) {
_ = database.CreateUser(&interfaces.User{})
}
Loading…
Cancel
Save