Skip to content

Commit 431c4d4

Browse files
authored
Merge pull request #97 from mutablelogic/v5
Add multipart forms
2 parents 93b4a2d + 4e0a86d commit 431c4d4

File tree

114 files changed

+2906
-269
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+2906
-269
lines changed

cmd/server/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
type CLI struct {
2020
ServiceCommands
21+
Service2Commands
2122

2223
PG struct {
2324
pgmanager.DatabaseCommands

cmd/server/service.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import (
1010
// Packages
1111
server "github.com/mutablelogic/go-server"
1212
helloworld "github.com/mutablelogic/go-server/npm/helloworld"
13-
auth_schema "github.com/mutablelogic/go-server/pkg/auth/schema"
14-
cert_schema "github.com/mutablelogic/go-server/pkg/cert/schema"
1513
httpresponse "github.com/mutablelogic/go-server/pkg/httpresponse"
16-
pgmanager_schema "github.com/mutablelogic/go-server/pkg/pgmanager/schema"
17-
pgqueue_schema "github.com/mutablelogic/go-server/pkg/pgqueue/schema"
1814
provider "github.com/mutablelogic/go-server/pkg/provider"
1915
ref "github.com/mutablelogic/go-server/pkg/ref"
2016
types "github.com/mutablelogic/go-server/pkg/types"
@@ -27,6 +23,7 @@ import (
2723
httpserver "github.com/mutablelogic/go-server/pkg/httpserver/config"
2824
ldap "github.com/mutablelogic/go-server/pkg/ldap/config"
2925
logger "github.com/mutablelogic/go-server/pkg/logger/config"
26+
metrics "github.com/mutablelogic/go-server/pkg/metrics/config"
3027
pg "github.com/mutablelogic/go-server/pkg/pgmanager/config"
3128
pgqueue "github.com/mutablelogic/go-server/pkg/pgqueue/config"
3229
)
@@ -116,7 +113,6 @@ func (cmd *ServiceRunCommand) Run(app server.Cmd) error {
116113
pgpool := config.(*pg.Config)
117114

118115
// Set router
119-
pgpool.Prefix = pgmanager_schema.APIPrefix
120116
if router, ok := provider.Task(ctx, "httprouter.main").(server.HTTPRouter); !ok || router == nil {
121117
return httpresponse.ErrInternalError.With("Invalid router")
122118
} else {
@@ -141,7 +137,6 @@ func (cmd *ServiceRunCommand) Run(app server.Cmd) error {
141137
auth := config.(*auth.Config)
142138

143139
// Set the router
144-
auth.Prefix = auth_schema.APIPrefix
145140
if router, ok := ref.Provider(ctx).Task(ctx, "httprouter.main").(server.HTTPRouter); !ok || router == nil {
146141
return httpresponse.ErrInternalError.With("Invalid router")
147142
} else {
@@ -162,7 +157,6 @@ func (cmd *ServiceRunCommand) Run(app server.Cmd) error {
162157
pgqueue := config.(*pgqueue.Config)
163158

164159
// Set the router
165-
pgqueue.Prefix = pgqueue_schema.APIPrefix
166160
if router, ok := ref.Provider(ctx).Task(ctx, "httprouter.main").(server.HTTPRouter); !ok || router == nil {
167161
return httpresponse.ErrInternalError.With("Invalid router")
168162
} else {
@@ -182,7 +176,6 @@ func (cmd *ServiceRunCommand) Run(app server.Cmd) error {
182176
certmanager := config.(*cert.Config)
183177

184178
// Set the router
185-
certmanager.Prefix = cert_schema.APIPrefix
186179
if router, ok := ref.Provider(ctx).Task(ctx, "httprouter.main").(server.HTTPRouter); !ok || router == nil {
187180
return httpresponse.ErrInternalError.With("Invalid router")
188181
} else {
@@ -228,6 +221,19 @@ func (cmd *ServiceRunCommand) Run(app server.Cmd) error {
228221
return nil
229222
}))
230223

224+
err = errors.Join(err, provider.Load("metrics", "main", func(ctx context.Context, label string, config server.Plugin) error {
225+
metrics := config.(*metrics.Config)
226+
227+
// Set the router
228+
if router, ok := ref.Provider(ctx).Task(ctx, "httprouter.main").(server.HTTPRouter); !ok || router == nil {
229+
return httpresponse.ErrInternalError.With("Invalid router")
230+
} else {
231+
metrics.Router = router
232+
}
233+
234+
return nil
235+
}))
236+
231237
if err != nil {
232238
return err
233239
}

cmd/server/service2.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
5+
// Packages
6+
server "github.com/mutablelogic/go-server"
7+
provider "github.com/mutablelogic/go-server/pkg/provider"
8+
parser "github.com/mutablelogic/go-server/pkg/provider/parser"
9+
)
10+
11+
///////////////////////////////////////////////////////////////////////////////
12+
// TYPES
13+
14+
type Service2Commands struct {
15+
// Run ServiceRunCommand `cmd:"" group:"SERVICE" help:"Run the service"`
16+
Run2 Service2RunCommand `cmd:"" group:"SERVICE" help:"Run the service with plugins"`
17+
}
18+
19+
type Service2RunCommand struct {
20+
Plugins []string `help:"Plugin paths" env:"PLUGIN_PATH"`
21+
Args []string `arg:"" help:"Configuration files"`
22+
}
23+
24+
///////////////////////////////////////////////////////////////////////////////
25+
// PUBLIC METHODS
26+
27+
func (cmd *Service2RunCommand) Run(app server.Cmd) error {
28+
// Create a provider by loading the plugins
29+
provider, err := provider.NewWithPlugins(cmd.Plugins...)
30+
if err != nil {
31+
return err
32+
}
33+
34+
// Create a parser of the config files
35+
parser, err := parser.New(provider.Plugins()...)
36+
if err != nil {
37+
return err
38+
}
39+
40+
// Parse the configuration files
41+
for _, path := range cmd.Args {
42+
if err := parser.Parse(path); err != nil {
43+
return err
44+
}
45+
}
46+
47+
return nil
48+
}

etc/testdata/httpserver.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"httpserver": {
3+
"main": {
4+
"port": 8080,
5+
"host": "localhost"
6+
}
7+
}
8+
}

npm/helloworld/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
"description": "Static files",
55
"main": "dist/index.js",
66
"scripts": {
7-
"dev": "esbuild src/index.ts src/index.html --bundle --loader:.html=copy --watch --outdir=dist --allow-overwrite --servedir=dist --banner:js=\"document.addEventListener('DOMContentLoaded', () => { new EventSource('/esbuild').addEventListener('change', () => location.reload()) });\"",
8-
"dist": "rm -fr dist && install -d dist && esbuild src/index.ts src/index.html --bundle --sourcemap --loader:.html=copy --outdir=dist --allow-overwrite",
7+
"dev": "esbuild src/index.ts src/index.html --bundle --loader:.html=copy --loader:.ttf=file --loader:.svg=file --watch --outdir=dist --allow-overwrite --servedir=dist --banner:js=\"document.addEventListener('DOMContentLoaded', () => { new EventSource('/esbuild').addEventListener('change', () => location.reload()) });\"",
8+
"dist": "rm -fr dist && install -d dist && esbuild src/index.ts src/index.html --bundle --sourcemap --loader:.html=copy --loader:.ttf=file --loader:.svg=file --outdir=dist --allow-overwrite",
99
"clean": "rm -fr dist"
1010
},
1111
"dependencies": {
12-
"tslib": "^2.5.2",
13-
"lit":"^3.3.0"
12+
"bootstrap-icons": "^1.13.1",
13+
"echarts": "^5.6.0",
14+
"lit": "^3.3.0",
15+
"tslib": "^2.5.2"
1416
},
1517
"devDependencies": {
1618
"esbuild": "^0.25.3",
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)