Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy committed Feb 14, 2023
1 parent 3b67d13 commit 436e8a1
Show file tree
Hide file tree
Showing 20 changed files with 100 additions and 218 deletions.
2 changes: 2 additions & 0 deletions extensions/pipelines/http/emulator/rod/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package rod

import (
Context "context"

"github.com/go-rod/rod"

"github.com/vortex14/gotyphoon/ctx"
)

Expand Down
1 change: 1 addition & 0 deletions extensions/pipelines/http/emulator/rod/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rod
import (
"context"
"fmt"

"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"

Expand Down
1 change: 1 addition & 0 deletions extensions/pipelines/http/emulator/rod/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/go-rod/rod"

"github.com/vortex14/gotyphoon/elements/forms"
"github.com/vortex14/gotyphoon/elements/models/task"
Errors "github.com/vortex14/gotyphoon/errors"
Expand Down
82 changes: 0 additions & 82 deletions extensions/pipelines/http/emulator/rod/test_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion extensions/pipelines/http/net-http/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func GetBody(client *http.Client, request *http.Request) (error, *string, *http.

var reader io.ReadCloser
switch response.Header.Get("Content-Encoding") {
case "gzip":
case GZIP:
reader, err = gzip.NewReader(response.Body)
if err != nil {
return Errors.ResponseHttpGzipDecodeError, nil, nil
Expand Down
6 changes: 4 additions & 2 deletions extensions/pipelines/http/net-http/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package net_http

import (
Context "context"
"github.com/PuerkitoBio/goquery"
"github.com/vortex14/gotyphoon/interfaces"
"net/http"

"github.com/PuerkitoBio/goquery"

"github.com/vortex14/gotyphoon/ctx"
"github.com/vortex14/gotyphoon/interfaces"
)

const (
Expand All @@ -17,6 +18,7 @@ const (
REQUEST = "request"
RESPONSE = "response"
DATA = "data"
GZIP = "gzip"
)

type ValidationCallback func(logger interfaces.LoggerInterface, response *http.Response, doc *goquery.Document) bool
Expand Down
61 changes: 0 additions & 61 deletions extensions/pipelines/http/net-http/installation-proxy-old.go

This file was deleted.

4 changes: 3 additions & 1 deletion extensions/pipelines/http/net-http/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"context"
b64 "encoding/base64"
"errors"
"net/url"

Gin "github.com/gin-gonic/gin"

"github.com/vortex14/gotyphoon/elements/forms"
"github.com/vortex14/gotyphoon/elements/models/label"
"github.com/vortex14/gotyphoon/extensions/servers/gin"
"github.com/vortex14/gotyphoon/interfaces"
"net/url"
)

var (
Expand Down
8 changes: 5 additions & 3 deletions extensions/pipelines/http/net-http/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package net_http
import (
"context"
"fmt"
"github.com/sirupsen/logrus"
"github.com/vortex14/gotyphoon/extensions/middlewares"
"github.com/vortex14/gotyphoon/log"
"net/http"
"net/url"

"github.com/vortex14/gotyphoon/extensions/middlewares"
"github.com/vortex14/gotyphoon/log"

"github.com/sirupsen/logrus"

"github.com/vortex14/gotyphoon/elements/forms"
"github.com/vortex14/gotyphoon/elements/models/label"
"github.com/vortex14/gotyphoon/elements/models/task"
Expand Down
9 changes: 5 additions & 4 deletions extensions/pipelines/http/net-http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ package net_http
import (
"context"
"fmt"
"github.com/avast/retry-go/v4"
"github.com/vortex14/gotyphoon/extensions/models"
"github.com/vortex14/gotyphoon/log"
"github.com/vortex14/gotyphoon/utils"
"net/http"
"os"

"github.com/avast/retry-go/v4"
"github.com/fatih/color"

"github.com/vortex14/gotyphoon/elements/forms"
"github.com/vortex14/gotyphoon/elements/models/label"
"github.com/vortex14/gotyphoon/elements/models/task"
Errors "github.com/vortex14/gotyphoon/errors"
"github.com/vortex14/gotyphoon/extensions/models"
"github.com/vortex14/gotyphoon/interfaces"
"github.com/vortex14/gotyphoon/log"
"github.com/vortex14/gotyphoon/utils"
)

func Request(
Expand Down
8 changes: 5 additions & 3 deletions extensions/pipelines/http/net-http/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ package net_http
import (
"bufio"
"fmt"
. "github.com/smartystreets/goconvey/convey"
Fake "github.com/vortex14/gotyphoon/extensions/data/fake"
"github.com/vortex14/gotyphoon/log"
"io"
"io/ioutil"
"os"
"strings"
"sync"
"testing"
"time"

. "github.com/smartystreets/goconvey/convey"

Fake "github.com/vortex14/gotyphoon/extensions/data/fake"
"github.com/vortex14/gotyphoon/log"
)

func init() {
Expand Down
9 changes: 5 additions & 4 deletions extensions/pipelines/http/net-http/test_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package net_http

import (
"context"
"net/http"
"testing"

. "github.com/smartystreets/goconvey/convey"

"github.com/vortex14/gotyphoon/elements/forms"
"github.com/vortex14/gotyphoon/elements/models/label"
"github.com/vortex14/gotyphoon/elements/models/task"
"github.com/vortex14/gotyphoon/extensions/data/fake"
"github.com/vortex14/gotyphoon/interfaces"
"github.com/vortex14/gotyphoon/log"

"context"
"net/http"
"testing"
)

func init() {
Expand Down
3 changes: 2 additions & 1 deletion extensions/pipelines/http/net-http/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package net_http

import (
"fmt"
"github.com/vortex14/gotyphoon/extensions/data/fake"
"net/http"

"github.com/vortex14/gotyphoon/extensions/data/fake"
)

func FormattingProxy(proxy string) string {
Expand Down
37 changes: 25 additions & 12 deletions extensions/pipelines/task-pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type TaskPipeline struct {
context context.Context,
task interfaces.TaskInterface,
logger interfaces.LoggerInterface,
) (error, context.Context)
) (error, context.Context)

Cn func(
err error,
Expand All @@ -29,7 +29,7 @@ type TaskPipeline struct {

func (t *TaskPipeline) UnpackCtx(
ctx context.Context,
) (bool, interfaces.TaskInterface, interfaces.LoggerInterface) {
) (bool, interfaces.TaskInterface, interfaces.LoggerInterface) {

okT, taskInstance := task.Get(ctx)
okL, logger := log.Get(ctx)
Expand All @@ -40,15 +40,24 @@ func (t *TaskPipeline) Run(
context context.Context,
reject func(pipeline interfaces.BasePipelineInterface, err error),
next func(ctx context.Context),
) {
) {

if t.Fn == nil { reject(t, Errors.TaskPipelineRequiredHandler); return }
if t.Fn == nil {
reject(t, Errors.TaskPipelineRequiredHandler)
return
}

ok,taskInstance, logger := t.UnpackCtx(context)
if !ok { reject(t, Errors.PipelineContexFailed); return }
ok, taskInstance, logger := t.UnpackCtx(context)
if !ok {
reject(t, Errors.PipelineContexFailed)
return
}

err, newContext := t.Fn(context, taskInstance, logger)
if err != nil { reject(t, err); return }
if err != nil {
reject(t, err)
return
}
next(newContext)
}

Expand All @@ -58,11 +67,15 @@ func (t *TaskPipeline) Cancel(
err error,
) {

if t.Cn == nil { return }
if t.Cn == nil {
return
}

ok,taskInstance, logger := t.UnpackCtx(context)
if !ok { return }
ok, taskInstance, _logger := t.UnpackCtx(context)
if !ok {
return
}

t.Cn(err, context, taskInstance, logger)
t.Cn(err, context, taskInstance, _logger)

}
}
Loading

0 comments on commit 436e8a1

Please sign in to comment.