first commit

master
DEV 3 years ago
commit 3c6675a59e

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/active.iml" filepath="$PROJECT_DIR$/.idea/active.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -0,0 +1,3 @@
module activething.com/go/core
go 1.22

@ -0,0 +1,89 @@
// ------------------------------------------------------------------------
// Project active
// Active Thing (activething.com) git.activething.com/go
//
// File name bytes.go
// Created by DEV
// Modified 07/03/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package results
type (
BytesResult interface {
IsError() bool // GResult implementation
Cause() error // GResult implementation
Success() []byte // GResult implementation
Value() any
}
BytesSuccess []byte
BytesError struct{ error }
)
func TupleBytesSuccess(bytes []byte) ([]byte, error) {
return bytes, nil
}
func TupleBytesError(err error) ([]byte, error) {
return nil, err
}
// BytesSuccess -> BytesResult Implementation
func MakeBytesSuccess(success []byte) BytesSuccess {
return success
}
func (_ BytesSuccess) IsError() bool {
return false
}
func (_ BytesSuccess) Cause() error {
return nil
}
func (s BytesSuccess) Success() []byte {
return s
}
func (s BytesSuccess) Value() any {
return s
}
// BytesError -> BytesResult Implementation
func MakeBytesError(cause error) BytesError {
return BytesError{cause}
}
func (e BytesError) IsError() bool {
return true
}
func (e BytesError) Cause() error {
return e.error
}
func (_ BytesError) Success() []byte {
return nil
}
func (_ BytesError) Value() any {
return nil
}

@ -0,0 +1,92 @@
// ------------------------------------------------------------------------
// Project active
// Active Thing (activething.com) git.activething.com/go
//
// File name result.go
// Created by DEV
// Modified 07/03/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package g
import "activething.com/go/core/results"
type (
Result[T any] interface {
results.Result
Success() T
}
ResultSuccess[T any] struct {
Result T
}
ResultError[T any] struct {
error
}
)
func TupleSuccess[T any](res T) (T, error) {
return res, nil
}
func TupleError[T any](err error) (T, error) {
var r T
return r, err
}
func MakeSuccess[T any](res T) ResultSuccess[T] {
return ResultSuccess[T]{res}
}
func (r ResultSuccess[T]) Success() T {
return r.Result
}
func (r ResultSuccess[T]) Value() any {
return r.Result
}
func (_ ResultSuccess[T]) IsError() bool {
return false
}
func (_ ResultSuccess[T]) Cause() error {
return nil
}
func MakeError[T any](err error) ResultError[T] {
return ResultError[T]{error: err}
}
func (r ResultError[T]) Success() T {
var zero T
return zero
}
func (r ResultError[T]) Value() any {
var zero T
return zero
}
func (_ ResultError[T]) IsError() bool {
return true
}
func (r ResultError[T]) Cause() error {
return r.error
}

@ -0,0 +1,3 @@
module activething.com/go/core/results
go 1.22

@ -0,0 +1,89 @@
// ------------------------------------------------------------------------
// Project active
// Active Thing (activething.com) git.activething.com/go
//
// File name int.go
// Created by DEV
// Modified 07/03/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package results
type (
IntResult interface {
IsError() bool // GResult implementation
Cause() error // GResult implementation
Success() int // GResult implementation
Value() any // GResult implementation
}
IntSuccess int
IntError struct{ error }
)
func TupleIntSuccess(result int) (int, error) {
return result, nil
}
func TupleIntError(err error) ([]byte, error) {
return nil, err
}
// IntSuccess -> Result, G.Result Implementation
func MakeIntSuccess(success int) IntSuccess {
return IntSuccess(success)
}
func (_ IntSuccess) IsError() bool {
return false
}
func (_ IntSuccess) Cause() error {
return nil
}
func (s IntSuccess) Value() any {
return s
}
func (s IntSuccess) Success() int {
return int(s)
}
// IntError -> Result, G.Result Implementation
func MakeIntError(cause error) IntError {
return IntError{cause}
}
func (e IntError) IsError() bool {
return true
}
func (e IntError) Cause() error {
return e.error
}
func (_ IntError) Value() any {
return 0
}
func (_ IntError) Success() int {
return 0
}

@ -0,0 +1,32 @@
// ------------------------------------------------------------------------
// Project active
// Active Thing (activething.com) git.activething.com/go
//
// File name result.go
// Created by DEV
// Modified 08/03/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package results
type (
Result interface {
IsError() bool
Cause() error
Value() any
}
)

@ -0,0 +1,85 @@
// ------------------------------------------------------------------------
// Project active
// Active Thing (activething.com) git.activething.com/go
//
// File name string.go
// Created by DEV
// Modified 07/03/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package results
type (
StringResult interface {
IsError() bool // GResult implementation
Cause() error // GResult implementation
Success() any // GResult implementation
Native() string
}
StringSuccess string
StringError struct{ error }
)
func TupleStringSuccess(result string) (string, error) {
return result, nil
}
func TupleStringError(err error) (string, error) {
return "", err
}
// StringSuccess -> Result, G.Result Implementation
func (_ StringSuccess) IsError() bool {
return false
}
func (_ StringSuccess) Cause() error {
return nil
}
func (s StringSuccess) Value() any {
return s
}
func (s StringSuccess) Success() string {
return string(s)
}
// StringError -> Result, G.Result Implementation
func MakeStringError(cause error) IntError {
return IntError{cause}
}
func (e StringError) IsError() bool {
return true
}
func (e StringError) Cause() error {
return e.error
}
func (_ StringError) Success() string {
return ""
}
func (_ StringError) Value() any {
return ""
}

@ -0,0 +1,30 @@
// ------------------------------------------------------------------------
// Project active
// Active Thing (activething.com) git.activething.com/go
//
// File name active.go
// Created by DEV
// Modified 07/03/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package string
import "unsafe"
func ToBytes(source string) []byte {
return unsafe.Slice(unsafe.StringData(source), len(source))
}

@ -0,0 +1,93 @@
// ------------------------------------------------------------------------
// Project active
// Active Thing (activething.com) git.activething.com/go
//
// File name strings.go
// Created by DEV
// Modified 07/03/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package string
type Strings []string
func MakeStrings(size, capacity int) Strings {
return make(Strings, size, capacity)
}
func (s Strings) Reset() Strings {
if s != nil {
return s[:0]
}
return s
}
func (s Strings) Has(value string) bool {
return s.Search(value) != -1
}
func (s Strings) Search(search string) int {
ln := len(s)
if ln == 0 {
return -1
}
if ln < 10 {
return s.searchLineal(search)
}
return s.searchBinary(search)
}
func (s Strings) searchLineal(search string) int {
for x := 0; x < len(s); x++ {
if s[x] == search {
return x
}
}
return -1
}
func (s Strings) searchBinary(search string) int {
lf := 0
rg := len(s) - 1
for lf <= rg {
md := (lf + rg) / 2
if s[md] == search {
return md
} else if s[md] < search {
lf = md + 1
} else {
rg = md - 1
}
}
return -1
}
func (s Strings) Append(value string) Strings {
return append(s, value)
}
func (s Strings) Len() int {
return len(s)
}
func (s Strings) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s Strings) Less(i, j int) bool {
return len(s[i]) < len(s[j])
}

@ -0,0 +1,8 @@
go 1.22
use (
./core
./core/results
)
Loading…
Cancel
Save

Powered by TurnKey Linux.