Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
caddyproxy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
caddyproxy
Commits
992ea229
Commit
992ea229
authored
Oct 07, 2024
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tls
parent
6ca129da
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
39 deletions
+50
-39
caddyapi.go
caddy/caddyapi.go
+16
-13
template.go
caddy/template.go
+2
-0
type.go
caddy/type.go
+6
-4
params.go
command/run/params.go
+21
-18
run.go
command/run/run.go
+1
-1
config.go
openapi/config.go
+4
-3
No files found.
caddy/caddyapi.go
View file @
992ea229
...
@@ -15,13 +15,14 @@ import (
...
@@ -15,13 +15,14 @@ import (
)
)
type
CaddyAPI
struct
{
type
CaddyAPI
struct
{
Url
string
// URL of the Caddy API
Url
string
// URL of the Caddy API
RootDir
string
// Root directory of the Caddy to store website files and .caddy files.
RootDir
string
// Root directory of the Caddy to store website files and .caddy files.
client
*
http
.
Client
MasterDomain
string
client
*
http
.
Client
}
}
func
NewCaddyAPI
(
url
string
,
root
string
)
*
CaddyAPI
{
func
NewCaddyAPI
(
url
string
,
root
string
,
master
string
)
*
CaddyAPI
{
return
&
CaddyAPI
{
Url
:
url
,
RootDir
:
root
,
client
:
&
http
.
Client
{}}
return
&
CaddyAPI
{
Url
:
url
,
RootDir
:
root
,
client
:
&
http
.
Client
{}
,
MasterDomain
:
master
}
}
}
func
(
c
*
CaddyAPI
)
buildPayloadForCreateWebsite
(
domain
string
,
root
string
)
(
string
,
error
)
{
func
(
c
*
CaddyAPI
)
buildPayloadForCreateWebsite
(
domain
string
,
root
string
)
(
string
,
error
)
{
...
@@ -45,13 +46,14 @@ func (c *CaddyAPI) buildPayloadForCreateWebsite(domain string, root string) (str
...
@@ -45,13 +46,14 @@ func (c *CaddyAPI) buildPayloadForCreateWebsite(domain string, root string) (str
return
buffer
.
String
(),
nil
return
buffer
.
String
(),
nil
}
}
func
(
c
*
CaddyAPI
)
newWebsiteCaddyFile
(
domain
string
,
root
string
)
error
{
func
(
c
*
CaddyAPI
)
newWebsiteCaddyFile
(
domain
string
,
root
string
,
master
string
)
error
{
buffer
:=
bytes
.
NewBufferString
(
""
)
buffer
:=
bytes
.
NewBufferString
(
""
)
caddypath
:=
filepath
.
Join
(
c
.
RootDir
,
fmt
.
Sprintf
(
"%s.caddy"
,
domain
))
caddypath
:=
filepath
.
Join
(
c
.
RootDir
,
fmt
.
Sprintf
(
"%s.caddy"
,
domain
))
// build CaddyFileTemplate.
// build CaddyFileTemplate.
cfg
:=
NewWebsiteCaddyFile
{
cfg
:=
NewWebsiteCaddyFile
{
DomainName
:
fmt
.
Sprintf
(
"https://%s"
,
domain
),
DomainName
:
fmt
.
Sprintf
(
"https://%s"
,
domain
),
RootDir
:
root
,
RootDir
:
root
,
MasterDomain
:
master
,
}
}
tmpl
,
err
:=
template
.
New
(
"test"
)
.
Parse
(
staticWebsiteCaddyFileTempl
)
tmpl
,
err
:=
template
.
New
(
"test"
)
.
Parse
(
staticWebsiteCaddyFileTempl
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -71,13 +73,14 @@ func (c *CaddyAPI) newWebsiteCaddyFile(domain string, root string) error {
...
@@ -71,13 +73,14 @@ func (c *CaddyAPI) newWebsiteCaddyFile(domain string, root string) error {
return
nil
return
nil
}
}
func
(
c
*
CaddyAPI
)
newForwardCaddyFile
(
from
string
,
to
string
)
error
{
func
(
c
*
CaddyAPI
)
newForwardCaddyFile
(
from
string
,
to
string
,
master
string
)
error
{
buffer
:=
bytes
.
NewBufferString
(
""
)
buffer
:=
bytes
.
NewBufferString
(
""
)
caddypath
:=
filepath
.
Join
(
c
.
RootDir
,
fmt
.
Sprintf
(
"%s.caddy"
,
from
))
caddypath
:=
filepath
.
Join
(
c
.
RootDir
,
fmt
.
Sprintf
(
"%s.caddy"
,
from
))
// build CaddyFileTemplate.
// build CaddyFileTemplate.
cfg
:=
ForwardWebsiteCaddyFile
{
cfg
:=
ForwardWebsiteCaddyFile
{
DomainName
:
fmt
.
Sprintf
(
"https://%s"
,
from
),
DomainName
:
fmt
.
Sprintf
(
"https://%s"
,
from
),
Target
:
to
,
Target
:
to
,
MasterDomain
:
master
,
}
}
tmpl
,
err
:=
template
.
New
(
"test"
)
.
Parse
(
forwardWebsiteCaddyFileTempl
)
tmpl
,
err
:=
template
.
New
(
"test"
)
.
Parse
(
forwardWebsiteCaddyFileTempl
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -159,7 +162,7 @@ func (c *CaddyAPI) CreateWebsite(domain string, resource string) error {
...
@@ -159,7 +162,7 @@ func (c *CaddyAPI) CreateWebsite(domain string, resource string) error {
return
err
return
err
}
}
// create caddyfile.
// create caddyfile.
if
err
:=
c
.
newWebsiteCaddyFile
(
domain
,
websiteRoot
);
err
!=
nil
{
if
err
:=
c
.
newWebsiteCaddyFile
(
domain
,
websiteRoot
,
c
.
MasterDomain
);
err
!=
nil
{
return
err
return
err
}
}
...
@@ -181,7 +184,7 @@ func (c *CaddyAPI) CreateWebsite(domain string, resource string) error {
...
@@ -181,7 +184,7 @@ func (c *CaddyAPI) CreateWebsite(domain string, resource string) error {
func
(
c
*
CaddyAPI
)
ForwardWebsite
(
param
types
.
ForwardWebsite
)
error
{
func
(
c
*
CaddyAPI
)
ForwardWebsite
(
param
types
.
ForwardWebsite
)
error
{
// create caddyfile.
// create caddyfile.
if
err
:=
c
.
newForwardCaddyFile
(
param
.
Domain
,
param
.
Target
);
err
!=
nil
{
if
err
:=
c
.
newForwardCaddyFile
(
param
.
Domain
,
param
.
Target
,
c
.
MasterDomain
);
err
!=
nil
{
return
err
return
err
}
}
...
...
caddy/template.go
View file @
992ea229
...
@@ -2,6 +2,7 @@ package caddy
...
@@ -2,6 +2,7 @@ package caddy
var
staticWebsiteCaddyFileTempl
=
`
var
staticWebsiteCaddyFileTempl
=
`
{{ .DomainName }} {
{{ .DomainName }} {
tls /certs/{{ .MasterDomain }}/{{ .MasterDomain }}.crt /certs/{{ .MasterDomain }}/{{ .MasterDomain }}.key
root * {{ .RootDir }}
root * {{ .RootDir }}
file_server
file_server
...
@@ -11,6 +12,7 @@ var staticWebsiteCaddyFileTempl = `
...
@@ -11,6 +12,7 @@ var staticWebsiteCaddyFileTempl = `
var
forwardWebsiteCaddyFileTempl
=
`
var
forwardWebsiteCaddyFileTempl
=
`
{{ .DomainName }} {
{{ .DomainName }} {
tls /certs/{{ .MasterDomain }}/{{ .MasterDomain }}.crt /certs/{{ .MasterDomain }}/{{ .MasterDomain }}.key
reverse_proxy https://{{ .Target }} {
reverse_proxy https://{{ .Target }} {
header_up Host {upstream_hostport}
header_up Host {upstream_hostport}
transport http {
transport http {
...
...
caddy/type.go
View file @
992ea229
package
caddy
package
caddy
type
NewWebsiteCaddyFile
struct
{
type
NewWebsiteCaddyFile
struct
{
DomainName
string
DomainName
string
RootDir
string
RootDir
string
MasterDomain
string
}
}
type
StaticWebsiteCreatePayload
struct
{
type
StaticWebsiteCreatePayload
struct
{
...
@@ -12,8 +13,9 @@ type StaticWebsiteCreatePayload struct {
...
@@ -12,8 +13,9 @@ type StaticWebsiteCreatePayload struct {
}
}
type
ForwardWebsiteCaddyFile
struct
{
type
ForwardWebsiteCaddyFile
struct
{
DomainName
string
DomainName
string
Target
string
Target
string
MasterDomain
string
}
}
type
ForwardWebsitePayload
struct
{
type
ForwardWebsitePayload
struct
{
...
...
command/run/params.go
View file @
992ea229
package
run
package
run
const
(
const
(
hostFlag
=
"host"
hostFlag
=
"host"
portFlag
=
"port"
portFlag
=
"port"
caddyUrlFlag
=
"caddy-url"
caddyUrlFlag
=
"caddy-url"
caddyRootFlag
=
"caddy-root"
caddyRootFlag
=
"caddy-root"
downloadDirFlag
=
"download-dir"
downloadDirFlag
=
"download-dir"
logFlag
=
"log"
masterDomainFlag
=
"master-domain"
logFlag
=
"log"
)
)
type
serviceParam
struct
{
type
serviceParam
struct
{
host
string
host
string
port
int
port
int
caddyUrl
string
caddyUrl
string
caddyRoot
string
caddyRoot
string
logPath
string
logPath
string
downloadDir
string
downloadDir
string
masterDomain
string
}
}
var
(
var
(
params
=
&
serviceParam
{
params
=
&
serviceParam
{
host
:
"0.0.0.0"
,
host
:
"0.0.0.0"
,
port
:
9000
,
port
:
9000
,
caddyUrl
:
""
,
caddyUrl
:
""
,
caddyRoot
:
""
,
caddyRoot
:
""
,
logPath
:
"/root/data/service.log"
,
logPath
:
"/root/data/service.log"
,
downloadDir
:
"/root/data/download"
,
downloadDir
:
"/root/data/download"
,
masterDomain
:
""
,
}
}
)
)
command/run/run.go
View file @
992ea229
...
@@ -92,7 +92,7 @@ func runCommand(cmd *cobra.Command, _ []string) {
...
@@ -92,7 +92,7 @@ func runCommand(cmd *cobra.Command, _ []string) {
}
}
}()
}()
capi
:=
caddy
.
NewCaddyAPI
(
params
.
caddyUrl
,
params
.
caddyRoot
)
capi
:=
caddy
.
NewCaddyAPI
(
params
.
caddyUrl
,
params
.
caddyRoot
,
params
.
masterDomain
)
api
:=
openapi
.
NewOpenAPI
(
&
openapi
.
Config
{
api
:=
openapi
.
NewOpenAPI
(
&
openapi
.
Config
{
Host
:
params
.
host
,
Host
:
params
.
host
,
...
...
openapi/config.go
View file @
992ea229
package
openapi
package
openapi
type
Config
struct
{
type
Config
struct
{
Host
string
Host
string
Port
int
Port
int
TempDir
string
// temp dir store download files.
TempDir
string
// temp dir store download files.
MasterDomain
string
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment