Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-orusapi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
orus-io
go-orusapi
Commits
c26b7fd68dd7
Commit
c26b7fd68dd7
authored
4 months ago
by
Christophe de Vienne
Browse files
Options
Downloads
Patches
Plain Diff
cmd: Fix & improve WithUI()
parent
849953bbb703
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#113920
failed
4 months ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/oapi.go
+0
-3
0 additions, 3 deletions
cmd/oapi.go
cmd/program_ui.go
+24
-8
24 additions, 8 deletions
cmd/program_ui.go
with
24 additions
and
11 deletions
cmd/oapi.go
+
0
−
3
View file @
c26b7fd6
package
cmd
import
(
"fmt"
"net/http"
"strconv"
...
...
@@ -66,5 +65,4 @@
return
func
(
program
*
Program
)
{
program
.
Version
.
APIVersion
=
oapi
.
Info
()
.
Title
+
" "
+
oapi
.
Info
()
.
Version
WithMiddleware
(
func
(
next
http
.
Handler
)
http
.
Handler
{
fmt
.
Println
(
"oapi middleware"
)
return
http
.
HandlerFunc
(
func
(
rw
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -70,5 +68,4 @@
return
http
.
HandlerFunc
(
func
(
rw
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
fmt
.
Println
(
"oapi"
,
r
.
URL
.
Path
)
if
r
.
URL
.
Path
==
"/swagger.json"
{
json
:=
oapi
.
JSON
()
rw
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
...
...
This diff is collapsed.
Click to expand it.
cmd/program_ui.go
+
24
−
8
View file @
c26b7fd6
...
...
@@ -16,7 +16,7 @@
fs
fs
.
FS
paths
[]
string
External
string
`long:"
ui-
external" ini-name:"
ui-ui-
external" description:"UI external server"`
External
string
`long:"external" ini-name:"external" description:"UI external server"`
}
func
NewIgnoreNotFoundResponseWriter
(
rw
http
.
ResponseWriter
)
*
IgnoreNotFoundResponseWriter
{
...
...
@@ -74,7 +74,22 @@
return
rw
.
next
.
Write
(
data
)
}
func
WithUI
(
uifs
fs
.
FS
,
prefix
string
)
Option
{
type
UIConfig
struct
{
Name
string
Description
string
Prefix
string
}
func
WithUI
(
uifs
fs
.
FS
,
cfg
*
UIConfig
)
Option
{
if
cfg
==
nil
{
cfg
=
&
UIConfig
{}
}
if
cfg
.
Name
==
""
{
cfg
.
Name
=
"ui"
}
if
cfg
.
Description
==
""
{
cfg
.
Description
=
"User Interface"
}
uiOptions
:=
UIOptions
{
fs
:
uifs
,
}
...
...
@@ -93,8 +108,8 @@
}
uiHandler
=
httputil
.
NewSingleHostReverseProxy
(
u
)
}
if
p
refix
!=
""
{
uiHandler
=
http
.
StripPrefix
(
p
refix
,
uiHandler
)
if
cfg
.
P
refix
!=
""
{
uiHandler
=
http
.
StripPrefix
(
cfg
.
P
refix
,
uiHandler
)
}
return
http
.
HandlerFunc
(
func
(
rw
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -98,8 +113,8 @@
}
return
http
.
HandlerFunc
(
func
(
rw
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
p
refix
!=
""
{
if
!
strings
.
HasPrefix
(
r
.
URL
.
Path
,
p
refix
)
{
if
cfg
.
P
refix
!=
""
{
if
!
strings
.
HasPrefix
(
r
.
URL
.
Path
,
cfg
.
P
refix
)
{
next
.
ServeHTTP
(
rw
,
r
)
}
}
...
...
@@ -122,7 +137,7 @@
var
serveFound
bool
for
_
,
cmd
:=
range
program
.
Parser
.
Commands
()
{
if
cmd
.
Name
==
"serve"
{
_
,
err
:=
cmd
.
AddGroup
(
"ui"
,
"User Interface"
,
&
uiOptions
)
g
,
err
:=
cmd
.
AddGroup
(
cfg
.
Name
,
cfg
.
Description
,
&
uiOptions
)
if
err
!=
nil
{
panic
(
err
)
}
...
...
@@ -126,6 +141,7 @@
if
err
!=
nil
{
panic
(
err
)
}
g
.
Namespace
=
cfg
.
Name
serveFound
=
true
break
...
...
@@ -134,6 +150,6 @@
if
!
serveFound
{
panic
(
"serve command not found"
)
}
})
})
(
program
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment