parent
7d3ec68bad
commit
1a4b3476e8
@ -0,0 +1,35 @@
|
|||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// Project atila
|
||||||
|
// Active Thing (activething.com) git.activething.com/go
|
||||||
|
//
|
||||||
|
// File name crypter.go
|
||||||
|
// Created by DEV
|
||||||
|
// Modified 16/02/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 crypts
|
||||||
|
|
||||||
|
|
||||||
|
type (
|
||||||
|
|
||||||
|
Crypter interface {
|
||||||
|
Encrypter
|
||||||
|
Decrypter
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// Project atila
|
||||||
|
// Active Thing (activething.com) git.activething.com/go
|
||||||
|
//
|
||||||
|
// File name encrypter.go
|
||||||
|
// Created by DEV
|
||||||
|
// Modified 16/02/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 crypts
|
||||||
|
|
||||||
|
import "activething.com/go/gogo/core/results"
|
||||||
|
|
||||||
|
type (
|
||||||
|
|
||||||
|
|
||||||
|
Encrypter interface {
|
||||||
|
Encrypt (data []byte) results.Bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
EncrypterNop struct {}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (_ EncrypterNop) Encrypt (_ []byte) results.Bytes {
|
||||||
|
return results.MakeBytesError(G.ErrNotImplemented) }
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
module activething.com/go/gogo/core/crypts
|
||||||
|
|
||||||
|
|
||||||
|
go 1.20
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// Project atila
|
||||||
|
// Active Thing (activething.com) git.activething.com/go
|
||||||
|
//
|
||||||
|
// File name gogo.go
|
||||||
|
// Created by DEV
|
||||||
|
// Modified 16/02/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 crypts
|
||||||
|
|
||||||
|
import "activething.com/go/gogo/core/errs"
|
||||||
|
|
||||||
|
var (
|
||||||
|
|
||||||
|
G = struct {
|
||||||
|
ErrNotImplemented errs.ErrCode
|
||||||
|
}{
|
||||||
|
ErrNotImplemented: errs.ErrCode("core:crypts.not-implemented"),
|
||||||
|
}
|
||||||
|
)
|
||||||
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* ---------------------------------------------------------
|
|
||||||
* Project $PROJECT_NAME
|
|
||||||
* Active Thing (activething.com) git.activething.com/go
|
|
||||||
*
|
|
||||||
* File name $FILE_NAME
|
|
||||||
* Created by ${USER}
|
|
||||||
* Modified ${DAY}/${MONTH}/${YEAR}
|
|
||||||
*
|
|
||||||
* Copyright ${YEAR} 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 opts
|
|
||||||
|
|
||||||
// Apply
|
|
||||||
// aplica una serie de funciones OptionFnc a un objeto dado y lo retorna modificado.
|
|
||||||
func Apply[T any](target *T, options ...OptionFnc[T]) *T {
|
|
||||||
if target == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
for _, fn := range options {
|
|
||||||
fn(target)
|
|
||||||
}
|
|
||||||
return target
|
|
||||||
}
|
|
||||||
|
|
||||||
// ApplyAndCheck
|
|
||||||
// aplica una serie de funciones OptionErrFnc a un objeto y retorna el objeto modificado,
|
|
||||||
// junto con un posible error en caso de configuración incorrecta.
|
|
||||||
func ApplyAndCheck[T any](target *T, options ...OptionErrFnc[T]) (*T, error) {
|
|
||||||
for _, fn := range options {
|
|
||||||
if err := fn(target); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return target, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ApplyAndCheckAll
|
|
||||||
// aplica una serie de funciones OptionErrFnc a un objeto y retorna el objeto modificado,
|
|
||||||
// junto con una lista de errores que se han producido durante la configuración.
|
|
||||||
func ApplyAndCheckAll[T any](target T, options ...OptionErrFnc[T]) (T, []error) {
|
|
||||||
var lst []error
|
|
||||||
for _, fn := range options {
|
|
||||||
if err := fn(&target); err != nil {
|
|
||||||
lst = append(lst, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return target, lst
|
|
||||||
}
|
|
||||||
@ -0,0 +1,66 @@
|
|||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// Project atila
|
||||||
|
// Active Thing (activething.com) git.activething.com/go
|
||||||
|
//
|
||||||
|
// File name r_bytes.go
|
||||||
|
// Created by DEV
|
||||||
|
// Modified 15/02/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 (
|
||||||
|
|
||||||
|
Bytes interface {
|
||||||
|
IsError () bool
|
||||||
|
Success () []byte
|
||||||
|
Error () error
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BytesSuccess []byte
|
||||||
|
|
||||||
|
BytesError struct {
|
||||||
|
error
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
func (_ BytesSuccess) IsError () bool { return false }
|
||||||
|
|
||||||
|
func (_ BytesSuccess) Error () error { return nil }
|
||||||
|
|
||||||
|
func (r BytesSuccess) Success () []byte { return r }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func MakeBytesError (cause error) BytesError {
|
||||||
|
return BytesError{ cause } }
|
||||||
|
|
||||||
|
func (_ BytesError) IsError () bool { return true }
|
||||||
|
|
||||||
|
func (_ BytesError) Success () []byte { return nil }
|
||||||
|
|
||||||
|
func (r BytesError) Error () error { return r.error }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
module activething.com/go/gogo/core/results
|
||||||
|
|
||||||
|
|
||||||
|
go 1.20
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// Project atila
|
||||||
|
// Active Thing (activething.com) git.activething.com/go
|
||||||
|
//
|
||||||
|
// File name packer_opts.go
|
||||||
|
// Created by DEV
|
||||||
|
// Modified 16/02/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 pjson
|
||||||
|
|
||||||
|
import (
|
||||||
|
"activething.com/go/gogo/core/crypts"
|
||||||
|
"activething.com/go/gogo/core/opts"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func PackerWithEncrypter (encrypter crypts.Encrypter) opts.OptionFnc[Packer] {
|
||||||
|
return func(p *Packer) {
|
||||||
|
if encrypter == nil {
|
||||||
|
encrypter = crypts.EncrypterNop{}
|
||||||
|
}
|
||||||
|
p.state.Encrypter = encrypter
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue