Fix save routes

This commit is contained in:
Александр Федорюк 2022-11-22 11:55:44 +03:00
parent 02b4c660e6
commit 7d54b6047a
6 changed files with 107 additions and 18 deletions

View File

@ -3,15 +3,14 @@ functions:
paths:
- path: /path/for/route
methods:
get: calcGet
post: calcPost
put: calcPut
get: test.calcGet
post: test.calcPost
put: test.calcPut
- path: /path/for/route2
methods:
get: convertGet
post: convertPost
put: convertPut
get: test.convertGet
post: test.convertPost
put: test.convertPut
proxy:
- domain: yt.com
paths:
@ -23,18 +22,17 @@ proxy:
paths:
- path: /path/for/route
redirect: domain.ltd/path/to/route
static:
- domain: yt.com
paths:
- path: /
files:
- index.html
- styles/style.css
- test/index.html
- test/styles/style.css
- path: /dir
dirs:
- imgs
- styles
- lib
- structs
params:
- name: gateway.s3.endpoint

View File

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"strings"
"yt-cli/structs"
"gopkg.in/yaml.v3"
@ -35,5 +36,70 @@ func ConfigUpload(filename string) {
}
}
fmt.Println(forUpload)
if len(forUpload.Static) > 0 {
for _, statics := range forUpload.Static {
if len(statics.Paths) > 0 {
for _, path := range statics.Paths {
if len(path.Files) > 0 {
for _, filename := range path.Files {
GatewayStaticFileSet(filename, statics.Domain, strings.ReplaceAll(fmt.Sprintf(`%s/%s`, path.Path, filename), "//", "/"))
}
}
if len(path.Dirs) > 0 {
for _, dirname := range path.Dirs {
GatewayStaticDirSet(statics.Domain, dirname, path.Path)
}
}
}
}
}
}
if len(forUpload.Functions) > 0 {
for _, domains := range forUpload.Functions {
if len(domains.Paths) > 0 {
for _, functionPath := range domains.Paths {
if functionPath.Methods.Get != nil {
GatewayFuncSet(domains.Domain, "GET", *functionPath.Methods.Get, functionPath.Path)
}
if functionPath.Methods.Head != nil {
GatewayFuncSet(domains.Domain, "HEAD", *functionPath.Methods.Head, functionPath.Path)
}
if functionPath.Methods.Post != nil {
GatewayFuncSet(domains.Domain, "POST", *functionPath.Methods.Post, functionPath.Path)
}
if functionPath.Methods.Put != nil {
GatewayFuncSet(domains.Domain, "PUT", *functionPath.Methods.Put, functionPath.Path)
}
if functionPath.Methods.Delete != nil {
GatewayFuncSet(domains.Domain, "DELETE", *functionPath.Methods.Delete, functionPath.Path)
}
if functionPath.Methods.Connect != nil {
GatewayFuncSet(domains.Domain, "CONNECT", *functionPath.Methods.Connect, functionPath.Path)
}
if functionPath.Methods.Options != nil {
GatewayFuncSet(domains.Domain, "OPTIONS", *functionPath.Methods.Options, functionPath.Path)
}
if functionPath.Methods.Trace != nil {
GatewayFuncSet(domains.Domain, "TRACE", *functionPath.Methods.Trace, functionPath.Path)
}
if functionPath.Methods.Patch != nil {
GatewayFuncSet(domains.Domain, "PATCH", *functionPath.Methods.Patch, functionPath.Path)
}
}
}
}
}
if len(forUpload.Proxy) > 0 {
for _, proxies := range forUpload.Proxy {
if len(proxies.Paths) > 0 {
for _, path := range proxies.Paths {
GatewayProxySet(proxies.Domain, path.Redirect, path.Path)
}
}
}
}
//fmt.Println(forUpload)
}

View File

@ -31,8 +31,8 @@ func GatewayStaticFileSet(filename, domain, gatewayPath string) {
}
paths := map[string]map[string]StaticContent{
"localhost": {
"func-static": StaticContent{
domain: {
gatewayPath: StaticContent{
ContentType: http.DetectContentType(file),
Content: file,
},

View File

@ -18,9 +18,15 @@ type FunctionPath struct {
}
type Methods struct {
Get string `json:"get"`
Post string `json:"post"`
Put string `json:"put"`
Get *string `json:"get,omitempty"`
Head *string `json:"head,omitempty"`
Post *string `json:"post,omitempty"`
Put *string `json:"put,omitempty"`
Delete *string `json:"delete,omitempty"`
Connect *string `json:"connect,omitempty"`
Options *string `json:"options,omitempty"`
Trace *string `json:"trace,omitempty"`
Patch *string `json:"patch,omitempty"`
}
type Param struct {

12
test/index.html Normal file
View File

@ -0,0 +1,12 @@
<html>
<head>
<link rel="stylesheet" href="styles/style.css" />
<title>Welcome to YT</title>
</head>
<h1>Добро пожаловать!</h1>
<p>Мы очень рады, что Вы выбрали нашу систему функций</p>
</html>

7
test/styles/style.css Normal file
View File

@ -0,0 +1,7 @@
h1 {
color: darkgreen;
}
p {
color: blue;
}