Skip to content

Commit

Permalink
Merge pull request #116 from ArtisanCloud/release/3.2.0
Browse files Browse the repository at this point in the history
proxy
  • Loading branch information
Matrix-X authored Dec 24, 2024
2 parents 1639b0f + d602798 commit 1497a75
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 104 deletions.
2 changes: 1 addition & 1 deletion cache/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ var (
ErrNotStored = errors.New("cache: item not stored")
ErrServerError = errors.New("cache: server error")
ErrInvalidValue = errors.New("cache: invalid value")
)
)
4 changes: 1 addition & 3 deletions cache/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ import (
const DEFAULT_EXPIRES_IN = 5
const DEFAULT_PURGE_EXPIRES_IN_PERIOD = 10



type MemCache struct {
*cache.Cache
cacheFile string
}

func NewMemCache(namespace string, defaultLifeTime time.Duration, directory string) CacheInterface {

if ACCache!=nil{
if ACCache != nil {
return ACCache
}

Expand Down
16 changes: 5 additions & 11 deletions datetime/carbon/carbonDatetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package carbon

import (
"github.com/golang-module/carbon"
"time"
)

type CarbonDatetime struct {
Expand All @@ -11,11 +10,12 @@ type CarbonDatetime struct {

var DefaultTimeZone = carbon.UTC

const DATETIME_FORMAT = "Y-m-d H:i:s"
const TIME_FORMAT = "H:i:s"
const (
DATETIME_FORMAT = "Y-m-d H:i:s"
TIME_FORMAT = "H:i:s"
)

func CreateCarbonDatetime(c carbon.Carbon) (dt *CarbonDatetime) {

dt = &CarbonDatetime{
&c,
}
Expand All @@ -34,11 +34,5 @@ func (dt *CarbonDatetime) SetTimezone(timezone string) *CarbonDatetime {
}

func GetCarbonNow() carbon.Carbon {
now := carbon.Now()

locProject, _ := time.LoadLocation(DefaultTimeZone)

now.Time = now.Time.In(locProject)

return now
return carbon.Now(DefaultTimeZone)
}
38 changes: 13 additions & 25 deletions datetime/carbon/carbonPeriod.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package carbon

import (
"errors"
"github.com/golang-module/carbon"
"reflect"
"time"

"github.com/golang-module/carbon"
)

type CarbonPeriod struct {
Expand All @@ -18,7 +19,6 @@ type CarbonPeriod struct {
}

func CreateCarbonPeriod() (p *CarbonPeriod) {

startDatetime := GetCarbonNow()
endDatetime := startDatetime.AddDay()
p = &CarbonPeriod{
Expand All @@ -28,12 +28,11 @@ func CreateCarbonPeriod() (p *CarbonPeriod) {
0,
0,
}
//fmt.Printf("%+v \r\n", p)
// fmt.Printf("%+v \r\n", p)
return p
}

func CreateCarbonPeriodWithCarbon(start *carbon.Carbon, end *carbon.Carbon) (p *CarbonPeriod) {

p = CreateCarbonPeriod()
p.startDatetime = start
p.endDatetime = end
Expand All @@ -42,7 +41,6 @@ func CreateCarbonPeriodWithCarbon(start *carbon.Carbon, end *carbon.Carbon) (p *
}

func CreateCarbonPeriodWithTime(start time.Time, end time.Time) (p *CarbonPeriod) {

startDate := carbon.Time2Carbon(start)
endDate := carbon.Time2Carbon(end)

Expand All @@ -54,7 +52,6 @@ func CreateCarbonPeriodWithTime(start time.Time, end time.Time) (p *CarbonPeriod
}

func CreateCarbonPeriodWithString(start string, end string, format string) (p *CarbonPeriod) {

if format == "" {
format = DATETIME_FORMAT
}
Expand All @@ -70,28 +67,25 @@ func CreateCarbonPeriodWithString(start string, end string, format string) (p *C
}

func (period *CarbonPeriod) SetStartDate(date interface{}, inclusive interface{}) *CarbonPeriod {

//fmt.Println("set start datetime")
// fmt.Println("set start datetime")
setDate(&period.startDatetime, date)
return period
}

func (period *CarbonPeriod) SetEndDate(date interface{}, inclusive interface{}) *CarbonPeriod {

//fmt.Println("set end datetime")
// fmt.Println("set end datetime")
setDate(&period.endDatetime, date)

return period
}

func setDate(toSetDate **carbon.Carbon, date interface{}) (err error) {
dType := reflect.TypeOf(date).String()
//fmt.Printf("%v\r\n", dType)
// fmt.Printf("%v\r\n", dType)
// 解析字符串
if dType == "string" {
parsedDate := carbon.Parse(date.(string))
if parsedDate.Error == nil {

*toSetDate = &parsedDate
} else {
err = errors.New("Invalid date string fmt.")
Expand All @@ -108,43 +102,37 @@ func setDate(toSetDate **carbon.Carbon, date interface{}) (err error) {
} else {
// 如果不是string或者*carbon.Carbon, 抛出panic
err = errors.New("Invalid date.")

}

return nil
}

func (period *CarbonPeriod) Overlaps(insideRange *CarbonPeriod) bool {

//fmt.Printf("start is : %#v", period.startDatetime.ToDateTimeString())
//fmt.Printf("current start :%s %d\r\n", period.startDatetime.ToString(), period.calculateStart())
//fmt.Printf("current end :%s %d\r\n", period.endDatetime.ToString(), period.calculateEnd())
//fmt.Printf("range start :%s %d\r\n", insideRange.startDatetime.ToString(), insideRange.calculateStart())
//fmt.Printf("range end :%s %d\r\n\n", insideRange.endDatetime.ToString(), insideRange.calculateEnd())
// fmt.Printf("start is : %#v", period.startDatetime.ToDateTimeString())
// fmt.Printf("current start :%s %d\r\n", period.startDatetime.ToString(), period.calculateStart())
// fmt.Printf("current end :%s %d\r\n", period.endDatetime.ToString(), period.calculateEnd())
// fmt.Printf("range start :%s %d\r\n", insideRange.startDatetime.ToString(), insideRange.calculateStart())
// fmt.Printf("range end :%s %d\r\n\n", insideRange.endDatetime.ToString(), insideRange.calculateEnd())

return period.calculateEnd() > insideRange.calculateStart() && insideRange.calculateEnd() > period.calculateStart()
}

func (period *CarbonPeriod) calculateStart() int64 {
return period.startDatetime.ToTimestamp()
return period.startDatetime.Timestamp()
}

func (period *CarbonPeriod) calculateEnd() int64 {
return period.endDatetime.ToTimestamp()
return period.endDatetime.Timestamp()
}

func (period *CarbonPeriod) DiffInDays() int64 {

diffDays := period.startDatetime.DiffInDays(*period.endDatetime)

return diffDays

}

func (period *CarbonPeriod) IsDiffInDays(inDays int64) bool {

diffDays := period.startDatetime.DiffInDaysWithAbs(*period.endDatetime)

return diffDays <= inDays

}
1 change: 0 additions & 1 deletion exception/exceptionInterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ type Throwable interface {
GetPrevious() *Throwable
__toString() string
}

18 changes: 6 additions & 12 deletions fmt/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func PrettyJson(data interface{}) (string, error) {
return buffer.String(), nil
}


func DD(datas ...interface{}) {
Dump(datas)
os.Exit(0)
Expand All @@ -40,19 +39,18 @@ func Dump(datas ...interface{}) {
func dump(data interface{}) {
var (
prettyJson interface{}
strData string
err error
strData string
err error
)
if data==nil{
if data == nil {
//fmt.Print("[nil]\r\n")

}else
if reflect.TypeOf(data).Kind() != reflect.String {
prettyJson,err = PrettyJson(data)
} else if reflect.TypeOf(data).Kind() != reflect.String {
prettyJson, err = PrettyJson(data)

} else {
strData = data.(string)
prettyJson,err = PrettyJson(strData)
prettyJson, err = PrettyJson(strData)
}

if err != nil {
Expand All @@ -61,10 +59,6 @@ func dump(data interface{}) {
fmt.Printf("%+v \r\n", prettyJson)
}





func PrintSlice(s []int) {
fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s)
}
5 changes: 3 additions & 2 deletions http/dataflow/dataflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"context"
"encoding/json"
"encoding/xml"
"github.com/ArtisanCloud/PowerLibs/v3/http/contract"
"github.com/pkg/errors"
"io"
"net/http"
"net/url"
"reflect"
"strings"

"github.com/ArtisanCloud/PowerLibs/v3/http/contract"
"github.com/pkg/errors"
)

type Dataflow struct {
Expand Down
17 changes: 13 additions & 4 deletions http/drivers/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@ func (c *Client) SetConfig(config *contract.ClientConfig) {
if config != nil {
c.conf = config
}
var proxy func(*http.Request) (*url.URL, error)
if config.ProxyURI != "" {
if proxyURL, err := url.Parse(config.ProxyURI); err == nil {
proxy = http.ProxyURL(proxyURL)
}
}
coreClient := http.Client{
Timeout: config.Timeout,
}
// todo set coreClient
if config.Cert.CertFile != "" && config.Cert.KeyFile != "" {
coreClient := http.Client{
Timeout: config.Timeout,
}
certPair, err := tls.LoadX509KeyPair(config.Cert.CertFile, config.Cert.KeyFile)
if err != nil {
err = errors.Wrap(err, "failed to load certificate")
Expand All @@ -70,8 +76,11 @@ func (c *Client) SetConfig(config *contract.ClientConfig) {
Certificates: []tls.Certificate{certPair},
}}
c.coreClient = &coreClient
} else if proxy != nil {
coreClient.Transport = &http.Transport{TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
}, Proxy: proxy}
}

}

// GetConfig 返回配置副本
Expand Down
2 changes: 1 addition & 1 deletion http/drivers/http/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func Test_NewClient(t *testing.T) {
if err != nil {
t.Error(err)
}

if helper == nil {
t.Error(err)
}
Expand Down
1 change: 1 addition & 0 deletions logger/lib/chown.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !linux
// +build !linux

package lumberjack
Expand Down
1 change: 1 addition & 0 deletions logger/lib/rotate_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux
// +build linux

package lumberjack
Expand Down
2 changes: 1 addition & 1 deletion media/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ func SaveImage(imgByte []byte, imgPath string, opts jpeg.Options) {
log.Println("encode error:", err)
}

}
}
6 changes: 1 addition & 5 deletions object/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import "reflect"

type Array []interface{}




func InArray(needle interface{}, hystack interface{}) bool {
switch key := needle.(type) {
case string:
Expand All @@ -33,7 +30,6 @@ func InArray(needle interface{}, hystack interface{}) bool {
return false
}


func SearchInArray(val interface{}, array interface{}) (exists bool, index int) {
exists = false
index = -1
Expand All @@ -57,4 +53,4 @@ func SearchInArray(val interface{}, array interface{}) (exists bool, index int)
func ArrayKeyExists(key interface{}, m map[interface{}]interface{}) bool {
_, ok := m[key]
return ok
}
}
7 changes: 4 additions & 3 deletions object/number.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func IsNumeric(val interface{}, trueNumber bool) bool {
return true
case string:

if trueNumber{
if trueNumber {
return false
}

Expand All @@ -23,7 +23,8 @@ func IsNumeric(val interface{}, trueNumber bool) bool {
if len(str) == 1 {
return false
}
str = str[1:] }
str = str[1:]
}
// hex
if len(str) > 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X') {
for _, h := range str[2:] {
Expand Down Expand Up @@ -54,4 +55,4 @@ func IsNumeric(val interface{}, trueNumber bool) bool {
}

return false
}
}
Loading

0 comments on commit 1497a75

Please sign in to comment.