Skip to content

Commit e7e4c92

Browse files
author
mirkobrombin
committed
docs: document plugins and plugins development in README
1 parent 6bd99fb commit e7e4c92

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,77 @@ Enable the TUI with the `--tui` flag when starting the server:
165165
goup start --tui
166166
```
167167

168+
## Plugins
169+
170+
GoUP! has a lightweight plugin system that allows you to extend its functionality.
171+
The following plugins are included:
172+
173+
- **Custom Header Plugin**: Adds custom headers to HTTP responses, configured per domain.
174+
- **PHP Plugin**: Handles `.php` requests using PHP-FPM.
175+
176+
### Enabling Plugins
177+
178+
To enable plugins, add their configuration in the `plugin_configs` section of
179+
the site's JSON configuration file. Example:
180+
181+
```json
182+
{
183+
"domain": "example.com",
184+
"port": 8080,
185+
"root_directory": "/path/to/root",
186+
"custom_headers": {
187+
"X-Custom-Header": "Hello, World!"
188+
},
189+
"plugin_configs": {
190+
"PHPPlugin": {
191+
"enable": true,
192+
"fpm_addr": "/run/php/php8.2-fpm.sock"
193+
}
194+
}
195+
}
196+
```
197+
198+
### Developing Plugins
199+
200+
You can create your own plugins by implementing the `Plugin` interface. Here’s a
201+
basic structure:
202+
203+
```go
204+
package myplugin
205+
206+
import (
207+
"net/http"
208+
"github.com/mirkobrombin/goup/internal/server/middleware"
209+
log "github.com/sirupsen/logrus"
210+
)
211+
212+
type MyPlugin struct{}
213+
214+
func (p *MyPlugin) Name() string {
215+
return "MyPlugin"
216+
}
217+
218+
func (p *MyPlugin) Init(mwManager *middleware.MiddlewareManager) error {
219+
return nil
220+
}
221+
222+
func (p *MyPlugin) InitForSite(mwManager *middleware.MiddlewareManager, logger *log.Logger, conf config.SiteConfig) error {
223+
mwManager.Use(func(next http.Handler) http.Handler {
224+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
225+
logger.Info("MyPlugin is working!")
226+
next.ServeHTTP(w, r)
227+
})
228+
})
229+
return nil
230+
}
231+
```
232+
233+
Then register your plugin in the `main.go` file:
234+
235+
```go
236+
pluginManager.Register(&myplugin.MyPlugin{})
237+
```
238+
168239
## Contributing
169240

170241
I really appreciate any contributions you would like to make, whether it's a

0 commit comments

Comments
 (0)