gufodao

package
v1.12.4 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Copyright 2020 Alexey Yanchenko <mail@yanchenko.me>

This file is part of the Gufo library.

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

View Source
var AesKey = []byte("H4fnCsMf4vbE60nK")

AesKey is salt for pasword hash

View Source
var Configpath string = "/var/gufo/config/"
View Source
var DBConnectionv2 = &DBv2{}

Connection instance

Functions

func AnsDef

func AnsDef(i int)

func AnsNo

func AnsNo()

func AskForConfigFile

func AskForConfigFile(i int)

func CheckConfig

func CheckConfig()

CheckConfig() Check configuration file and stop app if config file mot foud or has errors

func CheckDBStructure

func CheckDBStructure()

func CheckForFlags

func CheckForFlags()

func CheckForSign added in v1.11.5

func CheckForSign()

CheckForSign - check Gufo Sign and if it missing, generate a sign. Sign need to connect to micoservices. By this Sign Microservices understand that requests are from one system

func ConfigString

func ConfigString(conf string) string

func ConvertAnyToInterface

func ConvertAnyToInterface(anyValue *anypb.Any) (interface{}, error)

func ConvertInterfaceToAny

func ConvertInterfaceToAny(v interface{}) (*anypb.Any, error)

func CreateConfig

func CreateConfig()

func DBCheck

func DBCheck() bool

func DecryptConfigPasswords

func DecryptConfigPasswords(pwd string) string

DecryptConfigPasswords - Decrypt Hashed password in settings file to real password

func DelSession

func DelSession(sessionToken string)

func DerefString

func DerefString(s *string) string

func EncryptConfigPassword

func EncryptConfigPassword(pwd string) (string, error)

func ErrorReturn added in v1.11.5

func ErrorReturn(t *pb.Request, httpcode int, code string, message string) (response *pb.Response)

func GRPCDelete added in v1.12.2

func GRPCDelete(misroservice string, param string, paramid string, args map[string]interface{}, token string, sign string) map[string]interface{}

func GRPCGen added in v1.12.4

func GRPCGen(misroservice string, param string, paramid string, args map[string]interface{}, token string, method string, sign string) map[string]interface{}

func GRPCGet added in v1.12.2

func GRPCGet(misroservice string, param string, paramid string, args map[string]interface{}, token string, sign string) map[string]interface{}

func GRPCPatch added in v1.12.4

func GRPCPatch(misroservice string, param string, paramid string, args map[string]interface{}, token string, sign string) map[string]interface{}

func GRPCPost added in v1.12.2

func GRPCPost(misroservice string, param string, paramid string, args map[string]interface{}, token string, sign string) map[string]interface{}

func GRPCPut added in v1.12.2

func GRPCPut(misroservice string, param string, paramid string, args map[string]interface{}, token string, sign string) map[string]interface{}

func GRPCReq added in v1.12.2

func GRPCReq(misroservice string, param string, paramid string, args map[string]interface{}, token string, method string, sign string) map[string]interface{}

func GRPCTrace added in v1.12.4

func GRPCTrace(misroservice string, param string, paramid string, args map[string]interface{}, token string, sign string) map[string]interface{}

func GenString

func GenString(n int, alphanum string) string

GenerateStr func

func GetLogDir

func GetLogDir() string

func GetPass

func GetPass(conf string) string

func HashConfigPasswords

func HashConfigPasswords()

HashConfigPasswords - Change password in settings file to hash

func Hashgen

func Hashgen(n int) string

func InitCache

func InitCache()

func Int32

func Int32(v int) *int32

func Interfacetoresponse

func Interfacetoresponse(request *pb.Request, answer map[string]interface{}) (response *pb.Response)

func JsonGet added in v1.12.3

func JsonGet(url string, args map[string]interface{}, token string, tokentype string, tokenheader string) ([]byte, error)

func JsonReq added in v1.12.3

func JsonReq(url string, args map[string]interface{}, token string, tokentype string, tokenheader string, method string) ([]byte, error)

func Numgen

func Numgen(n int) string

func Pad

func Pad(src []byte) []byte

func RandomString

func RandomString(l int) string

func ReadUserIP

func ReadUserIP(r *http.Request) string

requestGetRemoteAddress returns ip address of the client making the request, taking into account http proxies

func SendHTMLEmail

func SendHTMLEmail(to string, title string, link []string, subject string, templ string, attach []string, ms *MailSettings)

func SetErrorLog

func SetErrorLog(value string)

func SetLog

func SetLog(value string)

func SetSession

func SetSession(name string, isAdmin int, completed int, readonly int) (sessionToken string, exptime int, err error)

func Stringen

func Stringen(n int) string

func ToMapStringAny

func ToMapStringAny(v map[string]interface{}) map[string]*anypb.Any

func ToMapStringInterface

func ToMapStringInterface(v map[string]*anypb.Any) map[string]interface{}

func Unpad

func Unpad(src []byte) ([]byte, error)

func UpdateSession

func UpdateSession(sessionToken string) map[string]interface{}

func WriteLog

func WriteLog(value string, p string)

func WriteTokenInRedis

func WriteTokenInRedis(sessionToken string, uid string, isadmin int, completed int, exptime int, readonly int)

Types

type APITokens

type APITokens struct {
	gorm.Model
	TokenId    string `gorm:"column:tokenid;type:varchar(60);UNIQUE;NOT NULL;"`
	Token      string `gorm:"column:token;type:varchar(254);UNIQUE;NOT NULL;"`
	TokenName  string `gorm:"column:tokenname;type:varchar(60);DEFAULT '';"`
	UID        string `gorm:"column:uid;type:varchar(60);NOT NULL;"`
	Created    int    `gorm:"column:created;type:int;DEFAULT '0'"`
	Expiration int    `gorm:"column:expiration;type:int;DEFAULT '0'"`    //if 0 - no expiration time
	Status     bool   `gorm:"column:status;type:bool;DEFAULT 'true'"`    // if true - active, if false - deactivated
	IsAdmin    bool   `gorm:"column:is_admin;type:bool;DEFAULT 'false'"` //only if generated by admin
	Readonly   bool   `gorm:"column:readonly;type:bool;DEFAULT 'false'"`
	Comment    string `gorm:"column:comment;type:varchar(60);DEFAULT '';"`
}

type DBv2

type DBv2 struct {
	Conn *gorm.DB
}

func ConnectDBv2

func ConnectDBv2() (*DBv2, error)

GetConnection - connect to DB

func DBConnectv2

func DBConnectv2() (*DBv2, error)

type Entrypoint

type Entrypoint struct {
	gorm.Model
	ID      string `gorm:"column:entrypointid;type:varchar(60);NOT NULL;"`
	Status  bool   `gorm:"column:status;type:bool;DEFAULT 'false'"`
	Version string `gorm:"column:version;type:varchar(254);UNIQUE;NOT NULL;"`
}

type ImpersonateTokens

type ImpersonateTokens struct {
	gorm.Model
	TokenId   string `gorm:"column:tokenid;type:varchar(60);UNIQUE;NOT NULL;"`
	Token     string `gorm:"column:token;type:varchar(254);UNIQUE;NOT NULL;"`
	UID       string `gorm:"column:uid;type:varchar(60);NOT NULL;"`
	Created   int    `gorm:"column:created;type:int;DEFAULT '0'"`
	CreatedBy string `gorm:"column:createdby;type:varchar(254);DEFAULT '';"`
}

type MailRequest

type MailRequest struct {
	// contains filtered or unexported fields
}

Request struct

func NewRequest

func NewRequest(to []string, subject, body string, attach []string) *MailRequest

func (*MailRequest) ParseTemplate

func (r *MailRequest) ParseTemplate(templateFileName string, data interface{}) error

func (*MailRequest) SendEmail

func (r *MailRequest) SendEmail(ms *MailSettings) (bool, error)

type MailSettings

type MailSettings struct {
	Custom  bool
	Host    string
	Port    string
	User    string
	Pass    string
	Address string
	Reply   string
	Title   string
}

type Response

type Response struct {
	Data      map[string]interface{} `json:"data"`
	Session   map[string]interface{} `json:"session"`
	TimeStamp int                    `json:"timestamp"`
	Language  string                 `json:"lang"`
}

type TimeHash

type TimeHash struct {
	gorm.Model
	UID      string `gorm:"column:uid;type:varchar(60);NOT NULL;"`
	Mail     string `gorm:"column:mail;type:varchar(254);DEFAULT '';"`
	Hash     string `gorm:"column:hash;type:varchar(254);DEFAULT '';"`
	Param    string `gorm:"column:param;type:varchar(254);DEFAULT '';"`
	Created  int    `gorm:"column:created;type:int;DEFAULT '0'"`
	Livetime int    `gorm:"column:livetime;type:int;DEFAULT '0'"`
}
type Roles struct {
	gorm.Model
	UID   string `gorm:"type:varchar(60);UNIQUE;NOT NULL;"`
	Admin bool   `gorm:"type:double;DEFAULT 'false'"`
}
type Settings struct {
	gorm.Model
	Email_Confirmation bool `gorm:"type:double;DEFAULT 'false'"`
	Registration       bool `gorm:"type:double;DEFAULT 'false'"`
}

Timehash table structure: Uid - users hash email - users email hash - 64 hash param - Which function create this record. We need confirm email in signup and change current password created - Where does record was created livetime - hash life time

type Users

type Users struct {
	gorm.Model
	UID           string `gorm:"column:uid;type:varchar(60);UNIQUE;NOT NULL;"`
	Name          string `gorm:"column:name;type:varchar(60);NOT NULL;DEFAULT '';UNIQUE"`
	Pass          string `gorm:"column:pass;type:varchar(128);NOT NULL;DEFAULT ''"`
	Mail          string `gorm:"column:mail;type:varchar(254);DEFAULT '';UNIQUE"`
	Mailsent      int    `gorm:"column:mailsent;type:int;DEFAULT '0'"`
	Mailconfirmed int    `gorm:"column:mailconfirmed;:int;DEFAULT '0'"`
	Created       int    `gorm:"column:created;type:int;DEFAULT '0'"`
	Access        int    `gorm:"column:access;type:int;DEFAULT '0'"`
	Login         int    `gorm:"column:login;type:int;DEFAULT '0'"`
	Status        bool   `gorm:"column:status;type:bool;DEFAULT 'false'"`
	Completed     bool   `gorm:"column:completed;type:bool;DEFAULT 'false'"`
	IsAdmin       bool   `gorm:"column:is_admin;type:bool;DEFAULT 'false'"`
	Readonly      bool   `gorm:"column:readonly;type:bool;DEFAULT 'false'"`
}

Jump to

Keyboard shortcuts

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