Skip to content

Commit

Permalink
Merge pull request #91 from vortex14/wb
Browse files Browse the repository at this point in the history
cors
  • Loading branch information
vortex14 authored Nov 30, 2023
2 parents 7b73f5b + 663ceed commit 57634a7
Show file tree
Hide file tree
Showing 13 changed files with 1,116 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ venv
build
tmp
main/ci/agent/agent
main
#main
build-errors.log
.air.toml
10 changes: 10 additions & 0 deletions elements/forms/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ func init() {
log.InitD()
}

func TestNewPipeline(t *testing.T) {
pl := &BasePipeline{MetaInfo: &label.MetaInfo{Name: "stage-1", Required: true}, Fn: func(ctx context.Context, logger interfaces.LoggerInterface) (error, context.Context) {
logger.Info("run stage 1")
return nil, ctx
}}

println(pl.Name)

}

func TestSkipStages(t *testing.T) {
Convey("skip stages", t, func() {
pg := &PipelineGroup{
Expand Down
11 changes: 6 additions & 5 deletions elements/forms/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import (
"crypto/md5"
"encoding/hex"
"fmt"
"github.com/fatih/color"
"github.com/fsnotify/fsnotify"
"github.com/go-git/go-git/v5"
"go.mongodb.org/mongo-driver/bson"
"gopkg.in/yaml.v2"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
"regexp"

"github.com/fatih/color"
"github.com/fsnotify/fsnotify"
"github.com/go-git/go-git/v5"
"go.mongodb.org/mongo-driver/bson"
"gopkg.in/yaml.v2"

"github.com/vortex14/gotyphoon/elements/models/awaitabler"
"github.com/vortex14/gotyphoon/elements/models/folder"
"github.com/vortex14/gotyphoon/elements/models/singleton"
Expand Down
67 changes: 32 additions & 35 deletions extensions/servers/gin/domains/fakes/fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
)

const (
NAME = "Fakes"
PATH = "/"
WATERMARK = "image.typhoon.dev"
DESCRIPTION = "Server for data fakes"
NAME = "Fakes"
PATH = "/"
WATERMARK = "image.typhoon.dev"
DESCRIPTION = "Server for data fakes"

ResourceName = "data fakers resource"
ResourceName = "data fakers resource"

FakeUPCPath = "upc"
FakeTaskPath = "task"
Expand All @@ -29,7 +29,6 @@ const (
FakeCustomerPath = "customer"
FakeCategoryPath = "category"
FakeCategoriesPath = "categories"

)

func Constructor(
Expand All @@ -40,44 +39,42 @@ func Constructor(
swaggerOptions *interfaces.SwaggerOptions,

) interfaces.ServerInterface {
return (
&gin.TyphoonGinServer{
TyphoonServer: &forms.TyphoonServer{
Port: port,
Level: interfaces.INFO,
MetaInfo: &label.MetaInfo{
Name : NAME,
Description : DESCRIPTION,
},
TracingOptions : tracingOptions,
LoggerOptions : loggerOptions,
SwaggerOptions : swaggerOptions,
return (&gin.TyphoonGinServer{
TyphoonServer: &forms.TyphoonServer{
Port: port,
Level: interfaces.INFO,
MetaInfo: &label.MetaInfo{
Name: NAME,
Description: DESCRIPTION,
},
}).
TracingOptions: tracingOptions,
LoggerOptions: loggerOptions,
},
}).
Init().
InitLogger().
AddResource(
&forms.Resource{
MetaInfo: &label.MetaInfo{
Path: PATH,
Name: ResourceName,
Path: "/",
Name: ResourceName,
Description: DESCRIPTION,
},
Actions: map[string]interfaces.ActionInterface{
ping.PATH : ping.Controller,
graph.PATH : graph.Controller,
FakeUPCPath : CreateUpcAction(),
FakeTaskPath : CreateTaskAction(),
FakeProxyPath : CreateProxyAction(),
FakeImagePath : CreateImageAction(),
FakeChargePath : CreateChargeAction(),
FakeProductPath : CrateProductAction(),
FakePaymentPath : CreatePaymentAction(),
FakeCategoryPath : CreateCategoryAction(),
FakeCustomerPath : CreateCustomerAction(),
FakeShippingPath : CreateShippingAction(),
FakeCategoriesPath : CreateCategoriesAction(),
ping.PATH: ping.Controller,
graph.PATH: graph.Controller,
FakeUPCPath: CreateUpcAction(),
FakeTaskPath: CreateTaskAction(),
FakeProxyPath: CreateProxyAction(),
FakeImagePath: CreateImageAction(),
FakeChargePath: CreateChargeAction(),
FakeProductPath: CrateProductAction(),
FakePaymentPath: CreatePaymentAction(),
FakeCategoryPath: CreateCategoryAction(),
FakeCustomerPath: CreateCustomerAction(),
FakeShippingPath: CreateShippingAction(),
FakeCategoriesPath: CreateCategoriesAction(),
},
},
)
}
}
13 changes: 12 additions & 1 deletion extensions/servers/gin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
Gin "github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"

"github.com/itsjamie/gin-cors"

swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"

Expand Down Expand Up @@ -142,7 +144,15 @@ func (s *TyphoonGinServer) SetRouterGroup(resource interfaces.ResourceInterface,
}

func (s *TyphoonGinServer) onCors() {

s.server.Use(cors.Middleware(cors.Config{
Origins: "*",
Methods: "GET, PUT, POST, DELETE",
RequestHeaders: "Origin, Authorization, Content-Type",
ExposedHeaders: "",
MaxAge: 50 * time.Second,
Credentials: false,
ValidateHeaders: false,
}))
}

func (s *TyphoonGinServer) OnStartGin(port int) error {
Expand All @@ -165,6 +175,7 @@ func (s *TyphoonGinServer) Init() interfaces.ServerInterface {
s.InitResourcesMap()

s.server = Gin.New()
s.onCors()
s.server.Use(Gin.Recovery())

if s.ActiveSwagger {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-retryablehttp v0.7.4
github.com/itchyny/gojq v0.12.13
github.com/itsjamie/gin-cors v0.0.0-20220228161158-ef28d3d2a0a8
github.com/kbinani/screenshot v0.0.0-20230812210009-b87d31814237
github.com/kelseyhightower/envconfig v1.4.0
github.com/mongodb/mongo-tools v0.0.0-20230816203804-9779cd4620f9
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ github.com/itchyny/gojq v0.12.13 h1:IxyYlHYIlspQHHTE0f3cJF0NKDMfajxViuhBLnHd/QU=
github.com/itchyny/gojq v0.12.13/go.mod h1:JzwzAqenfhrPUuwbmEz3nu3JQmFLlQTQMUcOdnu/Sf4=
github.com/itchyny/timefmt-go v0.1.5 h1:G0INE2la8S6ru/ZI5JecgyzbbJNs5lG1RcBqa7Jm6GE=
github.com/itchyny/timefmt-go v0.1.5/go.mod h1:nEP7L+2YmAbT2kZ2HfSs1d8Xtw9LY8D2stDBckWakZ8=
github.com/itsjamie/gin-cors v0.0.0-20220228161158-ef28d3d2a0a8 h1:3n0c+dqwjqfvvoV+Q3hWvXT58q/YGnegkFx8w56Kj44=
github.com/itsjamie/gin-cors v0.0.0-20220228161158-ef28d3d2a0a8/go.mod h1:AYdLvrSBFloDBNt7Y8xkQ6gmhCODGl8CPikjyIOnNzA=
github.com/jarcoal/httpmock v1.2.0 h1:gSvTxxFR/MEMfsGrvRbdfpRUMBStovlSRLw0Ep1bwwc=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
Expand Down
7 changes: 7 additions & 0 deletions main/astg/group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

const GroupName = "andy"

func reTRALL() {

}
58 changes: 58 additions & 0 deletions main/astg/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import (
"fmt"
"go/ast"
"go/parser"
"go/token"
)

func main() {
// borrowed from https://github.com/lukehoban/go-outline/blob/master/main.go#L54-L107
fset := token.NewFileSet()
parserMode := parser.ParseComments
var fileAst *ast.File
var err error

fileAst, err = parser.ParseFile(fset, "group.go", `package main
const GroupName = "andy"
func reTRALL() {
}
`, parserMode)
if err != nil {
panic(err)
}

for _, d := range fileAst.Decls {
switch decl := d.(type) {
case *ast.FuncDecl:

println(decl.Name.String())

fmt.Println()
fmt.Println("Func ??? ")

case *ast.GenDecl:
for _, spec := range decl.Specs {
switch spec := spec.(type) {
case *ast.ImportSpec:
fmt.Println("Import", spec.Path.Value)
case *ast.TypeSpec:
fmt.Println("Type", spec.Name.String())
case *ast.ValueSpec:
for _, id := range spec.Names {
fmt.Printf("Var %s: %v", id.Name, id.Obj.Decl.(*ast.ValueSpec).Values[0].(*ast.BasicLit).Value)
}
default:
fmt.Printf("Unknown token type: %s\n", decl.Tok)
}
}
default:
println(fmt.Sprintf("Unknown declaration @ %+v", decl.Pos()))
//fmt.Printf("Unknown declaration @\n", decl.Pos())
}
}
}
Loading

0 comments on commit 57634a7

Please sign in to comment.