Skip to content

Commit

Permalink
dataflow-filter-export (#160)
Browse files Browse the repository at this point in the history
* 提炼dataflow,filter,export子包

* 加一点测试代码
  • Loading branch information
guonaihong committed Jan 10, 2020
1 parent b43173e commit ba9f1f7
Show file tree
Hide file tree
Showing 38 changed files with 994 additions and 648 deletions.
60 changes: 0 additions & 60 deletions curl.go

This file was deleted.

128 changes: 0 additions & 128 deletions curl_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion context.go → dataflow/context.go
@@ -1,4 +1,4 @@
package gout
package dataflow

import (
"github.com/guonaihong/gout/decode"
Expand Down
8 changes: 4 additions & 4 deletions context_test.go → dataflow/context_test.go
@@ -1,4 +1,4 @@
package gout
package dataflow

import (
"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -51,7 +51,7 @@ func TestContext_BindBodyJSON(t *testing.T) {
path := []string{"200", "500"}
count := 0
for _, p := range path {
err := Def().GET(ts.URL + "/" + p).Callback(func(c *Context) error {
err := New().GET(ts.URL + "/" + p).Callback(func(c *Context) error {
assert.NotEqual(t, c.Code, 404)

switch c.Code {
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestContext_BindBodyYAML(t *testing.T) {
path := []string{"200", "500"}
count := 0
for _, p := range path {
err := Def().GET(ts.URL + "/" + p).Callback(func(c *Context) error {
err := New().GET(ts.URL + "/" + p).Callback(func(c *Context) error {
assert.NotEqual(t, c.Code, 404)

switch c.Code {
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestContext_BindBodyXML(t *testing.T) {
path := []string{"200", "500"}
count := 0
for _, p := range path {
err := Def().GET(ts.URL + "/" + p).Callback(func(c *Context) error {
err := New().GET(ts.URL + "/" + p).Callback(func(c *Context) error {
assert.NotEqual(t, c.Code, 404)

switch c.Code {
Expand Down
29 changes: 19 additions & 10 deletions dataflow.go → dataflow/dataflow.go
@@ -1,4 +1,4 @@
package gout
package dataflow

import (
"context"
Expand Down Expand Up @@ -72,7 +72,7 @@ func (df *DataFlow) OPTIONS(url string) *DataFlow {

// SetHost set host
func (df *DataFlow) SetHost(host string) *DataFlow {
if df.err != nil {
if df.Err != nil {
return df
}

Expand All @@ -84,7 +84,7 @@ func (df *DataFlow) SetHost(host string) *DataFlow {

// SetURL set url
func (df *DataFlow) SetURL(url string) *DataFlow {
if df.err != nil {
if df.Err != nil {
return df
}

Expand Down Expand Up @@ -158,7 +158,7 @@ func (df *DataFlow) UnixSocket(path string) *DataFlow {

transport, ok := df.out.Client.Transport.(*http.Transport)
if !ok {
df.Req.err = fmt.Errorf("UnixSocket:not found http.transport:%T", df.out.Client.Transport)
df.Req.Err = fmt.Errorf("UnixSocket:not found http.transport:%T", df.out.Client.Transport)
return df
}

Expand All @@ -173,7 +173,7 @@ func (df *DataFlow) UnixSocket(path string) *DataFlow {
func (df *DataFlow) SetProxy(proxyURL string) *DataFlow {
proxy, err := url.Parse(modifyURL(proxyURL))
if err != nil {
df.Req.err = err
df.Req.Err = err
return df
}

Expand All @@ -183,7 +183,7 @@ func (df *DataFlow) SetProxy(proxyURL string) *DataFlow {

transport, ok := df.out.Client.Transport.(*http.Transport)
if !ok {
df.Req.err = fmt.Errorf("SetProxy:not found http.transport:%T", df.out.Client.Transport)
df.Req.Err = fmt.Errorf("SetProxy:not found http.transport:%T", df.out.Client.Transport)
return df
}

Expand Down Expand Up @@ -280,17 +280,26 @@ func (df *DataFlow) Debug(d ...interface{}) *DataFlow {
return df
}

func (df *DataFlow) IsDebug() bool {
return df.out.opt.Debug
}

// Do send function
func (df *DataFlow) Do() (err error) {
return df.Req.Do()
}

// Filter filter function, use this function to turn on the filter function
func (df *DataFlow) Filter() *Filter {
return &Filter{df: df}
func (df *DataFlow) Filter() *filter {
return &filter{df: df}
}

// Export filter function, use this function to turn on the filter function
func (df *DataFlow) Export() *Export {
return &Export{df: df}
func (df *DataFlow) Export() *export {
return &export{df: df}
}

func (df *DataFlow) SetGout(out *Gout) {
df.out = out
df.Req.g = out
}

0 comments on commit ba9f1f7

Please sign in to comment.