mirror of
https://github.com/bettercap/bettercap
synced 2025-07-15 01:23:42 -07:00
new: properly exposing module handlers and parameters from api.rest
This commit is contained in:
parent
87ac32cd6b
commit
b98db78926
4 changed files with 64 additions and 22 deletions
|
@ -2,6 +2,7 @@ package session
|
|||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"regexp"
|
||||
|
@ -117,3 +118,24 @@ func (p ModuleParam) Help(padding int) string {
|
|||
func (p ModuleParam) Register(s *Session) {
|
||||
s.Env.Set(p.Name, p.Value)
|
||||
}
|
||||
|
||||
type JSONModuleParam struct {
|
||||
Name string `json:"name"`
|
||||
Type ParamType `json:"type"`
|
||||
Description string `json:"description"`
|
||||
Value string `json:"default_value"`
|
||||
Validator string `json:"validator"`
|
||||
}
|
||||
|
||||
func (p ModuleParam) MarshalJSON() ([]byte, error) {
|
||||
j := JSONModuleParam{
|
||||
Name: p.Name,
|
||||
Type: p.Type,
|
||||
Description: p.Description,
|
||||
Value: p.Value,
|
||||
}
|
||||
if p.Validator != nil {
|
||||
j.Validator = p.Validator.String()
|
||||
}
|
||||
return json.Marshal(j)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue