Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rym-util
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengqiuyun
rym-util
Commits
b7c45506
Commit
b7c45506
authored
Aug 17, 2022
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初始化
parent
025e4980
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
27 deletions
+14
-27
GlobalException.go
exception/GlobalException.go
+6
-15
Error.go
getWay/Error.go
+8
-8
Header.go
getWay/Header.go
+0
-4
No files found.
exception/GlobalException.go
View file @
b7c45506
package
exception
import
(
"errors"
"git.168cad.top/zhengqiuyun/rym-util/log"
"github.com/go-playground/validator/v10"
"reflect"
"strings"
)
func
ThrowsErr
(
err
error
)
{
if
err
!=
nil
{
log
.
Error
(
err
.
Error
())
panic
(
err
)
}
panic
(
err
)
}
func
ThrowsValid
(
err
error
,
r
interface
{})
{
...
...
@@ -21,7 +16,7 @@ func ThrowsValid(err error, r interface{}) {
case
validator
.
ValidationErrors
:
e
:=
(
err
)
.
(
validator
.
ValidationErrors
)
errMsg
:=
getError
(
e
,
r
)
panic
(
errors
.
New
(
errMsg
)
)
panic
(
DError
{
Code
:
"REQUEST_PARAMS_ERR"
,
Err
:
errMsg
}
)
break
default
:
panic
(
err
)
...
...
@@ -57,21 +52,17 @@ type DError struct {
Code
string
}
func
ThrowsErrS
(
err
string
)
{
if
&
err
!=
nil
&&
err
!=
""
{
log
.
Error
(
err
)
panic
(
DError
{
Err
:
err
})
}
func
ThrowsErrS
(
code
,
err
string
)
{
panic
(
DError
{
Code
:
code
,
Err
:
err
})
}
func
AssertThrowableErr
(
throwable
bool
,
err
error
)
{
if
throwable
{
log
.
Error
(
err
.
Error
())
panic
(
err
)
ThrowsErr
(
err
)
}
}
func
AssertThrowable
(
throwable
bool
,
code
,
err
string
)
{
if
throwable
{
panic
(
DError
{
Code
:
code
,
Err
:
err
}
)
ThrowsErrS
(
code
,
err
)
}
}
getWay/Error.go
View file @
b7c45506
...
...
@@ -3,7 +3,9 @@ package getWay
import
"github.com/gin-gonic/gin"
type
Error
struct
{
Code
State
Code
State
SubCode
string
SubMsg
string
}
func
ExceptionGetWayCatch
(
c
*
gin
.
Context
)
{
...
...
@@ -12,20 +14,18 @@ func ExceptionGetWayCatch(c *gin.Context) {
switch
err
.
(
type
)
{
case
Error
:
e
:=
(
err
)
.
(
Error
)
FailGetWay
(
c
,
e
.
Code
)
FailGetWay
(
c
,
e
.
Code
,
e
.
SubCode
,
e
.
SubMsg
)
break
}
}
}
func
ThrowsGetWayErr
(
code
State
)
{
if
&
code
!=
nil
{
panic
(
Error
{
code
})
}
func
ThrowsGetWayErr
(
code
State
,
subCode
,
subMsg
string
)
{
panic
(
Error
{
Code
:
code
,
SubCode
:
subCode
,
SubMsg
:
subMsg
})
}
func
AssertThrowsGetWayErr
(
throwable
bool
,
code
State
)
{
func
AssertThrowsGetWayErr
(
throwable
bool
,
code
State
,
subCode
,
subMsg
string
)
{
if
throwable
{
panic
(
Error
{
code
}
)
ThrowsGetWayErr
(
code
,
subCode
,
subMsg
)
}
}
getWay/Header.go
View file @
b7c45506
package
getWay
import
(
"git.168cad.top/zhengqiuyun/rym-util/exception"
"github.com/gin-gonic/gin"
)
...
...
@@ -26,9 +25,6 @@ func SetToken(v string, c *gin.Context) {
func
GetPlatformCode
(
c
*
gin
.
Context
)
string
{
platformCode
:=
getHeader
(
c
,
headerKeyPlatformCode
)
if
platformCode
==
""
{
exception
.
ThrowsErrS
(
"平台错误"
)
}
return
platformCode
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment