mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-06 01:24:16 +08:00
62e6c9bc6c
* Add a storage layer for attachments * Fix some bug * fix test * Fix copyright head and lint * Fix bug * Add setting for minio and flags for migrate-storage * Add documents * fix lint * Add test for minio store type on attachments * fix test * fix test * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Add warning when storage migrated successfully * Fix drone * fix test * rebase * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * refactor the codes * add trace * Fix test * remove log on xorm * Fi download bug * Add a storage layer for attachments * Add setting for minio and flags for migrate-storage * fix lint * Add test for minio store type on attachments * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Fix drone * fix test * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * refactor the codes * add trace * Fix test * Add URL function to serve attachments directly from S3/Minio * Add ability to enable/disable redirection in attachment configuration * Fix typo * Add a storage layer for attachments * Add setting for minio and flags for migrate-storage * fix lint * Add test for minio store type on attachments * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Fix drone * fix test * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * don't change unrelated files * Fix lint * Fix build * update go.mod and go.sum * Use github.com/minio/minio-go/v6 * Remove unused function * Upgrade minio to v7 and some other improvements * fix lint * Fix go mod Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Tyler <tystuyfzand@gmail.com>
167 lines
2.8 KiB
Go
Vendored
167 lines
2.8 KiB
Go
Vendored
package jsoniter
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
)
|
|
|
|
type stringAny struct {
|
|
baseAny
|
|
val string
|
|
}
|
|
|
|
func (any *stringAny) Get(path ...interface{}) Any {
|
|
if len(path) == 0 {
|
|
return any
|
|
}
|
|
return &invalidAny{baseAny{}, fmt.Errorf("GetIndex %v from simple value", path)}
|
|
}
|
|
|
|
func (any *stringAny) Parse() *Iterator {
|
|
return nil
|
|
}
|
|
|
|
func (any *stringAny) ValueType() ValueType {
|
|
return StringValue
|
|
}
|
|
|
|
func (any *stringAny) MustBeValid() Any {
|
|
return any
|
|
}
|
|
|
|
func (any *stringAny) LastError() error {
|
|
return nil
|
|
}
|
|
|
|
func (any *stringAny) ToBool() bool {
|
|
str := any.ToString()
|
|
if str == "0" {
|
|
return false
|
|
}
|
|
for _, c := range str {
|
|
switch c {
|
|
case ' ', '\n', '\r', '\t':
|
|
default:
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (any *stringAny) ToInt() int {
|
|
return int(any.ToInt64())
|
|
|
|
}
|
|
|
|
func (any *stringAny) ToInt32() int32 {
|
|
return int32(any.ToInt64())
|
|
}
|
|
|
|
func (any *stringAny) ToInt64() int64 {
|
|
if any.val == "" {
|
|
return 0
|
|
}
|
|
|
|
flag := 1
|
|
startPos := 0
|
|
if any.val[0] == '+' || any.val[0] == '-' {
|
|
startPos = 1
|
|
}
|
|
|
|
if any.val[0] == '-' {
|
|
flag = -1
|
|
}
|
|
|
|
endPos := startPos
|
|
for i := startPos; i < len(any.val); i++ {
|
|
if any.val[i] >= '0' && any.val[i] <= '9' {
|
|
endPos = i + 1
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
parsed, _ := strconv.ParseInt(any.val[startPos:endPos], 10, 64)
|
|
return int64(flag) * parsed
|
|
}
|
|
|
|
func (any *stringAny) ToUint() uint {
|
|
return uint(any.ToUint64())
|
|
}
|
|
|
|
func (any *stringAny) ToUint32() uint32 {
|
|
return uint32(any.ToUint64())
|
|
}
|
|
|
|
func (any *stringAny) ToUint64() uint64 {
|
|
if any.val == "" {
|
|
return 0
|
|
}
|
|
|
|
startPos := 0
|
|
|
|
if any.val[0] == '-' {
|
|
return 0
|
|
}
|
|
if any.val[0] == '+' {
|
|
startPos = 1
|
|
}
|
|
|
|
endPos := startPos
|
|
for i := startPos; i < len(any.val); i++ {
|
|
if any.val[i] >= '0' && any.val[i] <= '9' {
|
|
endPos = i + 1
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
parsed, _ := strconv.ParseUint(any.val[startPos:endPos], 10, 64)
|
|
return parsed
|
|
}
|
|
|
|
func (any *stringAny) ToFloat32() float32 {
|
|
return float32(any.ToFloat64())
|
|
}
|
|
|
|
func (any *stringAny) ToFloat64() float64 {
|
|
if len(any.val) == 0 {
|
|
return 0
|
|
}
|
|
|
|
// first char invalid
|
|
if any.val[0] != '+' && any.val[0] != '-' && (any.val[0] > '9' || any.val[0] < '0') {
|
|
return 0
|
|
}
|
|
|
|
// extract valid num expression from string
|
|
// eg 123true => 123, -12.12xxa => -12.12
|
|
endPos := 1
|
|
for i := 1; i < len(any.val); i++ {
|
|
if any.val[i] == '.' || any.val[i] == 'e' || any.val[i] == 'E' || any.val[i] == '+' || any.val[i] == '-' {
|
|
endPos = i + 1
|
|
continue
|
|
}
|
|
|
|
// end position is the first char which is not digit
|
|
if any.val[i] >= '0' && any.val[i] <= '9' {
|
|
endPos = i + 1
|
|
} else {
|
|
endPos = i
|
|
break
|
|
}
|
|
}
|
|
parsed, _ := strconv.ParseFloat(any.val[:endPos], 64)
|
|
return parsed
|
|
}
|
|
|
|
func (any *stringAny) ToString() string {
|
|
return any.val
|
|
}
|
|
|
|
func (any *stringAny) WriteTo(stream *Stream) {
|
|
stream.WriteString(any.val)
|
|
}
|
|
|
|
func (any *stringAny) GetInterface() interface{} {
|
|
return any.val
|
|
}
|