cast

package
v0.3.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2023 License: Apache-2.0 Imports: 2 Imported by: 5

Documentation

Overview

Copyright 2023 The acquirecloud Authors

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.

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 cast contains some utility functions for casting types. The first version contains the cast of the simple types (int, string, bool, etc.) to cast their scalar variables to the pointers and pointers to the variables of the simple types to the variables of the types. The casting maybe useful when it needs to distinguish whether a value is passed from the default values (in JSON objects, for example). In this case the target golang structures may use pointers to the types instead of the concrete types to understand whether a value was not provided (pointer is nil), or what its value if it is provided.

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(b *bool, def bool) bool

Bool returns *b or def if b == nil

func BoolPtr

func BoolPtr(b bool) *bool

BoolPtr returns pointer to bool value which is equal to b

func ByteArrayToString

func ByteArrayToString(buf []byte) string

ByteArrayToString turns a slice of bytes to string, without extra memory allocations

NOTE! Using this function is extremely dangerous, so it can be used with extra care with clear understanding how it works

func Int

func Int(i *int, def int) int

Int returns *i if i != nil or def

func Int64

func Int64(i *int64, def int64) int64

Int64 returns *i if i != nil or def

func Int64Ptr

func Int64Ptr(i int64) *int64

Int64Ptr returns pointer to the int64 value which is equal to i

func IntPtr

func IntPtr(i int) *int

IntPtr returns pointer to the int value which is equal to i

func Ptr

func Ptr[T any](v T) *T

Ptr is a generic function, which returns pointer to the type provided (v)

func String

func String(s *string, def string) string

String turns the string pointer to the string type

func StringPtr

func StringPtr(s string) *string

StringPtr returns address of s

func StringToByteArray

func StringToByteArray(v string) []byte

StringToByteArray gets a string and turns it to []byte without extra memory allocations

NOTE! Using this function is extremely dangerous, so it can be used with extra care with clear understanding how it works

func Value

func Value[T any](v *T, def T) T

Value is a generic function which allows to turn a pointer to the value of the ptr, or to the def, if the pointer is nil

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL