Skip to content
Snippets Groups Projects
Commit b4eca83a authored by Md. Alim Ul Karim's avatar Md. Alim Ul Karim :speech_balloon:
Browse files

Merge branch 'featue/improvements-v4' into 'develop'

"Enums improved" "Request Type"

## Introduction

"Enums improved" "Request Type"

Note: [Template Reference](https://hackmd.io/@akarimevatix/H1Qsmq23w)

## Worked on Items

- [x] "Enums improved" 
- [x] "Request Type"

## TODOs

- [ ] ....

## References

- N/A

## Notes

- N/A

## Performed full package

- [x] Code reformat

## Analysis CheckList

- [x] Run + add screenshot of CodeInspect

![image](/uploads/4847fcac93a4dfd385b2c0a85cdb8a7f/image.png)

- [x] Run `Go Install` on root

![image](/uploads/7cb48e3f9f02b3dafc6d60c08c6bae04/image.png)

- [x] Run `go tests/test` successfully [no failing tests]

![image](/uploads/cb64dfa3080008d73d5c81f26b3d8a88/image.png)
- [x] Run `go run cmd/main/main.go` successfully [no build fail]

![image](/uploads/5ba43615da38078163b1593a1c67fd1b/image.png)

See merge request !48
parents b2a6388e 43e01a83
Branches release/v0.4.6
Tags v0.4.6
1 merge request!48"Enums improved" "Request Type"
Showing
with 320 additions and 19 deletions
......@@ -7,6 +7,18 @@ import (
type Variant byte
func (v Variant) ToNumberString() string {
return basicEnumImpl.ToNumberString(v.Value())
}
func (v Variant) Name() string {
return basicEnumImpl.ToEnumString(v.Value())
}
func (v Variant) UnmarshallEnumToValue(jsonUnmarshallingValue []byte) (byte, error) {
panic("implement me")
}
func (v Variant) MarshalJSON() ([]byte, error) {
return basicEnumImpl.ToEnumJsonBytes(v.Value()), nil
}
......
......@@ -3,22 +3,33 @@ package main
import (
"fmt"
"gitlab.com/evatix-go/core/chmodhelper"
"gitlab.com/evatix-go/core/chmodhelper/chmodins"
"gitlab.com/evatix-go/core/coredata/corestr"
"gitlab.com/evatix-go/core/reqtype"
)
func main() {
rwx := chmodins.RwxOwnerGroupOther{
Owner: "rwx",
Group: "r--",
Other: "-wx",
}
// rwx := chmodins.RwxOwnerGroupOther{
// Owner: "rwx",
// Group: "r--",
// Other: "-wx",
// }
//
// fmt.Println(rwx.String())
// wrapper, _ := chmodhelper.NewUsingRwxOwnerGroupOther(&rwx)
fmt.Println(rwx.String())
wrapper, _ := chmodhelper.NewUsingRwxOwnerGroupOther(&rwx)
// fmt.Println(wrapper.ToRwxOwnerGroupOther().String())
//
// for name, variation := range linuxtype.RangesMap {
// fmt.Println(name, variation.Name(), variation.Value(), variation.String(), variation.ToNumberString())
// }
//
// for name, variation := range reqtype.RangesMap {
// fmt.Println(name, variation.Name(), variation.Value(), variation.String(), variation.ToNumberString())
// fmt.Println(variation.IsCrudOrSkip())
// fmt.Println("IsCreate OR Merge:", variation.IsAnyOfReqs(reqtype.Create, reqtype.Merge))
// }
fmt.Println(wrapper.ToRwxOwnerGroupOther().String())
fmt.Println(reqtype.RangesNotMeetError("", reqtype.Create, reqtype.Merge))
// items := &[]string{
// "00",
......
package coreapi
import "gitlab.com/evatix-go/core/coredata/coredynamic"
type GenericRequestIn struct {
Attribute *RequestAttribute `json:"Attribute,omitempty"`
Request interface{} `json:"Request,omitempty"`
}
func (receiver *GenericRequestIn) SimpleGenericRequest(
isValid bool,
invalidMessage string,
) *SimpleGenericRequest {
return &SimpleGenericRequest{
Attribute: receiver.Attribute,
Request: coredynamic.NewSimpleRequest(receiver.Request, isValid, invalidMessage),
}
}
package coreapi
import "gitlab.com/evatix-go/core/coredata/coredynamic"
type GenericResponse struct {
Attribute *ResponseAttribute `json:"Attribute,omitempty"`
Response interface{} `json:"Response,omitempty"`
}
func (receiver GenericResponse) GenericResponseResult() *GenericResponseResult {
return &GenericResponseResult{
Attribute: receiver.Attribute,
Response: coredynamic.NewSimpleResult(
receiver,
receiver.Attribute.IsValid,
receiver.Attribute.InvalidMessage),
}
}
package coreapi
import "gitlab.com/evatix-go/core/coredata/coredynamic"
type GenericResponseResult struct {
Attribute *ResponseAttribute `json:"Attribute,omitempty"`
Response *coredynamic.SimpleResult `json:"Response,omitempty"`
}
package coreapi
type PageRequest struct {
PageSize int
PageIndex int
}
package coreapi
import (
"gitlab.com/evatix-go/core/reqtype"
)
type RequestAttribute struct {
Url string `json:"Url,omitempty"`
Host string `json:"Host,omitempty"`
ResourceName string `json:"ResourceName,omitempty"`
RequestType reqtype.Request
SearchRequest *SearchRequest `json:"SearchRequest,omitempty"`
PageRequest *PageRequest `json:"PageRequest,omitempty"`
}
package coreapi
import "gitlab.com/evatix-go/core/reqtype"
type ResponseAttribute struct {
ResponseOfRequestType reqtype.Request
Count int
HasAnyRecord bool
NextPageRequestUrl string
StepsPerformed *[]string `json:"StepsPerformed,omitempty"`
DebugInfos *[]string `json:"DebugInfos,omitempty"`
HttpCode int
HttpMethod reqtype.Request
IsValid bool
InvalidMessage string `json:"InvalidMessage,omitempty"`
}
package coreapi
type SearchRequest struct {
SearchTerm string
IsNaturalSearch, IsContains, IsStartsWith, IsEndsWith, IsRegex bool
}
package coreapi
import "gitlab.com/evatix-go/core/coredata/coredynamic"
type SimpleGenericRequest struct {
Attribute *RequestAttribute `json:"Attribute,omitempty"`
Request *coredynamic.SimpleRequest `json:"Request,omitempty"`
}
......@@ -206,12 +206,24 @@ func (receiver *Dynamic) IsStruct() bool {
return receiver.ReflectKind() == reflect.Struct
}
func (receiver *Dynamic) IsFunc() bool {
return receiver.ReflectKind() == reflect.Func
}
func (receiver *Dynamic) IsSliceOrArray() bool {
k := receiver.ReflectKind()
return k == reflect.Slice || k == reflect.Array
}
func (receiver *Dynamic) IsSliceOrArrayOrMap() bool {
k := receiver.ReflectKind()
return k == reflect.Slice ||
k == reflect.Array ||
k == reflect.Map
}
func (receiver *Dynamic) IsMap() bool {
return receiver.ReflectKind() == reflect.Map
}
......
package stringslice
import "gitlab.com/evatix-go/core/constants"
func PrependNew(firstSlice []string, additionalItems ...string) *[]string {
sliceLength := len(firstSlice)
additionalItemsLength := len(additionalItems)
newSlice := make(
[]string,
constants.Zero,
sliceLength+additionalItemsLength)
if additionalItemsLength > 0 {
newSlice = append(newSlice, additionalItems...)
}
if sliceLength > 0 {
newSlice = append(newSlice, firstSlice...)
}
return &newSlice
}
package enumimpl
import (
"fmt"
"gitlab.com/evatix-go/core/constants"
"gitlab.com/evatix-go/core/converters"
"gitlab.com/evatix-go/core/defaulterr"
"gitlab.com/evatix-go/core/msgtype"
)
type BasicByte struct {
......@@ -60,6 +63,20 @@ func NewBasicByteUsingIndexedSlice(
byte(max))
}
func (receiver *BasicByte) IsAnyOf(value byte, givenBytes ...byte) bool {
if len(givenBytes) == 0 {
return true
}
for _, givenByte := range givenBytes {
if value == givenByte {
return true
}
}
return false
}
func (receiver *BasicByte) Max() byte {
return receiver.maxVal
}
......@@ -92,6 +109,7 @@ func (receiver *BasicByte) IsValidRange(value byte) bool {
return value >= receiver.minVal && value <= receiver.maxVal
}
// ToEnumJsonBytes used for MarshalJSON from map
func (receiver *BasicByte) ToEnumJsonBytes(value byte) []byte {
return receiver.jsonBytesHashmap[value]
}
......@@ -100,7 +118,14 @@ func (receiver *BasicByte) ToEnumString(value byte) string {
return *converters.UnsafeBytesToStringPtr(receiver.jsonBytesHashmap[value])
}
func (receiver *BasicByte) JsonBytesToValue(
func (receiver *BasicByte) ToNumberString(valueInRawFormat interface{}) string {
return fmt.Sprintf(constants.SprintValueFormat, valueInRawFormat)
}
// UnmarshallEnumToValue Mostly used for UnmarshalJSON
//
// Given bytes string enum value and transpile to exact enum raw value using map
func (receiver *BasicByte) UnmarshallEnumToValue(
jsonUnmarshallingValue []byte,
) (byte, error) {
if jsonUnmarshallingValue == nil {
......@@ -113,7 +138,11 @@ func (receiver *BasicByte) JsonBytesToValue(
if !has {
return constants.Zero,
defaulterr.UnMarshalling
msgtype.MeaningFulErrorWithData(
msgtype.UnMarshallingFailed,
"UnmarshallEnumToValue",
defaulterr.UnMarshallingPlusCannotFindingEnumMap,
string(jsonUnmarshallingValue))
}
return v, nil
......
package enumimpl
import (
"fmt"
"gitlab.com/evatix-go/core/constants"
"gitlab.com/evatix-go/core/converters"
"gitlab.com/evatix-go/core/defaulterr"
"gitlab.com/evatix-go/core/msgtype"
)
type BasicInt16 struct {
......@@ -42,6 +45,20 @@ func NewBasicInt16(
}
}
func (receiver *BasicInt16) IsAnyOf(value int16, checkingItems ...int16) bool {
if len(checkingItems) == 0 {
return true
}
for _, givenByte := range checkingItems {
if value == givenByte {
return true
}
}
return false
}
func (receiver *BasicInt16) Max() int16 {
return receiver.maxVal
}
......@@ -74,6 +91,7 @@ func (receiver *BasicInt16) IsValidRange(value int16) bool {
return value >= receiver.minVal && value <= receiver.maxVal
}
// ToEnumJsonBytes used for MarshalJSON from map
func (receiver *BasicInt16) ToEnumJsonBytes(value int16) []byte {
return receiver.jsonBytesHashmap[value]
}
......@@ -82,7 +100,14 @@ func (receiver *BasicInt16) ToEnumString(value int16) string {
return *converters.UnsafeBytesToStringPtr(receiver.jsonBytesHashmap[value])
}
func (receiver *BasicInt16) JsonBytesToValue(
func (receiver *BasicInt16) ToNumberString(valueInRawFormat interface{}) string {
return fmt.Sprintf(constants.SprintValueFormat, valueInRawFormat)
}
// UnmarshallEnumToValue Mostly used for UnmarshalJSON
//
// Given bytes string enum value and transpile to exact enum raw value using map
func (receiver *BasicInt16) UnmarshallEnumToValue(
jsonUnmarshallingValue []byte,
) (int16, error) {
if jsonUnmarshallingValue == nil {
......@@ -94,7 +119,11 @@ func (receiver *BasicInt16) JsonBytesToValue(
v, has := receiver.hashMap[str]
if !has {
return constants.Zero, defaulterr.UnMarshalling
return constants.Zero, msgtype.MeaningFulErrorWithData(
msgtype.UnMarshallingFailed,
"UnmarshallEnumToValue",
defaulterr.UnMarshallingPlusCannotFindingEnumMap,
string(jsonUnmarshallingValue))
}
return v, nil
......
package enumimpl
import (
"fmt"
"gitlab.com/evatix-go/core/constants"
"gitlab.com/evatix-go/core/converters"
"gitlab.com/evatix-go/core/defaulterr"
"gitlab.com/evatix-go/core/msgtype"
)
type BasicInt32 struct {
......@@ -38,6 +41,20 @@ func NewBasicInt32(
}
}
func (receiver *BasicInt32) IsAnyOf(value int32, checkingItems ...int32) bool {
if len(checkingItems) == 0 {
return true
}
for _, givenByte := range checkingItems {
if value == givenByte {
return true
}
}
return false
}
func (receiver *BasicInt32) Max() int32 {
return receiver.maxVal
}
......@@ -70,6 +87,7 @@ func (receiver *BasicInt32) IsValidRange(value int32) bool {
return value >= receiver.minVal && value <= receiver.maxVal
}
// ToEnumJsonBytes used for MarshalJSON from map
func (receiver *BasicInt32) ToEnumJsonBytes(value int32) []byte {
return receiver.jsonBytesHashmap[value]
}
......@@ -78,7 +96,14 @@ func (receiver *BasicInt32) ToEnumString(value int32) string {
return *converters.UnsafeBytesToStringPtr(receiver.jsonBytesHashmap[value])
}
func (receiver *BasicInt32) JsonBytesToValue(
func (receiver *BasicInt32) ToNumberString(valueInRawFormat interface{}) string {
return fmt.Sprintf(constants.SprintValueFormat, valueInRawFormat)
}
// UnmarshallEnumToValue Mostly used for UnmarshalJSON
//
// Given bytes string enum value and transpile to exact enum raw value using map
func (receiver *BasicInt32) UnmarshallEnumToValue(
jsonUnmarshallingValue []byte,
) (int32, error) {
if jsonUnmarshallingValue == nil {
......@@ -91,7 +116,11 @@ func (receiver *BasicInt32) JsonBytesToValue(
if !has {
return constants.Zero,
defaulterr.UnMarshalling
msgtype.MeaningFulErrorWithData(
msgtype.UnMarshallingFailed,
"UnmarshallEnumToValue",
defaulterr.UnMarshallingPlusCannotFindingEnumMap,
string(jsonUnmarshallingValue))
}
return v, nil
......
package enumimpl
import (
"fmt"
"gitlab.com/evatix-go/core/constants"
"gitlab.com/evatix-go/core/converters"
"gitlab.com/evatix-go/core/defaulterr"
"gitlab.com/evatix-go/core/msgtype"
)
type BasicInt8 struct {
......@@ -42,6 +45,20 @@ func NewBasicInt8(
}
}
func (receiver *BasicInt8) IsAnyOf(value int8, checkingItems ...int8) bool {
if len(checkingItems) == 0 {
return true
}
for _, givenByte := range checkingItems {
if value == givenByte {
return true
}
}
return false
}
func (receiver *BasicInt8) Max() int8 {
return receiver.maxVal
}
......@@ -74,6 +91,7 @@ func (receiver *BasicInt8) IsValidRange(value int8) bool {
return value >= receiver.minVal && value <= receiver.maxVal
}
// ToEnumJsonBytes used for MarshalJSON from map
func (receiver *BasicInt8) ToEnumJsonBytes(value int8) []byte {
return receiver.jsonBytesHashmap[value]
}
......@@ -82,7 +100,14 @@ func (receiver *BasicInt8) ToEnumString(value int8) string {
return *converters.UnsafeBytesToStringPtr(receiver.jsonBytesHashmap[value])
}
func (receiver *BasicInt8) JsonBytesToValue(
func (receiver *BasicInt8) ToNumberString(valueInRawFormat interface{}) string {
return fmt.Sprintf(constants.SprintValueFormat, valueInRawFormat)
}
// UnmarshallEnumToValue Mostly used for UnmarshalJSON
//
// Given bytes string enum value and transpile to exact enum raw value using map
func (receiver *BasicInt8) UnmarshallEnumToValue(
jsonUnmarshallingValue []byte,
) (int8, error) {
if jsonUnmarshallingValue == nil {
......@@ -94,7 +119,11 @@ func (receiver *BasicInt8) JsonBytesToValue(
v, has := receiver.hashMap[str]
if !has {
return constants.Zero, defaulterr.UnMarshalling
return constants.Zero, msgtype.MeaningFulErrorWithData(
msgtype.UnMarshallingFailed,
"UnmarshallEnumToValue",
defaulterr.UnMarshallingPlusCannotFindingEnumMap,
string(jsonUnmarshallingValue))
}
return v, nil
......
......@@ -41,6 +41,20 @@ func NewBasicString(
}
}
func (receiver *BasicString) IsAnyOf(value string, checkingItems ...string) bool {
if len(checkingItems) == 0 {
return true
}
for _, givenByte := range checkingItems {
if value == givenByte {
return true
}
}
return false
}
func (receiver *BasicString) Max() string {
return receiver.maxVal
}
......@@ -65,11 +79,15 @@ func (receiver *BasicString) IsValidRange(value string) bool {
return receiver.hashset[value]
}
// ToEnumJsonBytes used for MarshalJSON from map
func (receiver *BasicString) ToEnumJsonBytes(value string) []byte {
return receiver.jsonBytesHashmap[value]
}
func (receiver *BasicString) JsonBytesToValue(
// UnmarshallEnumToValue Mostly used for UnmarshalJSON
//
// Given bytes string enum value and transpile to exact enum raw value using map
func (receiver *BasicString) UnmarshallEnumToValue(
jsonUnmarshallingValue []byte,
) (string, error) {
if jsonUnmarshallingValue == nil {
......
package coreinterface
type ByteIsAnyOfChecker interface {
IsAnyOf(value byte, checkingItems ...byte) bool
}
package coreinterface
type Int16IsAnyOfChecker interface {
IsAnyOf(value int16, checkingItems ...int16) bool
}
package coreinterface
type StringIsAnyOfChecker interface {
IsAnyOf(value string, checkingItems ...string) bool
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment