model

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: MIT Imports: 2 Imported by: 40

README

Estructuras que utilizo con frecuencia en proyectos escritos en Go

ejemplo de uso en una tabla

func Patient() *model.Object {
	run_Global := input.RunGlobal{
		PlaceHolder: "ch ej: 13173472-7 dni ej: 12345678 ",
	}
	textOnly := input.TextOnly{}
	phoneNumber := input.Number{Pattern: `^[0-9]{7,11}$`}

	dateAge := input.DateAge{}

	t := model.Object{
		Noun:           "patient",
		TextFieldNames: []string{"patient_name"},
		Fields: []model.Field{
			
            {Name: "id_patient", DataType: "TEXT", Legend: "Id", Input: pkHiddenNoRequiredInView, NotRenderHtml: true},
			
            {Name: "patient_run", DataType: "TEXT", Unique: true, Legend: "Run o Dni", Input: run_Global},
			
            {Name: "patient_name", DataType: "TEXT", Legend: "Nombre y Apellido(s)", Input: textOnly},
			
            {Name: "patient_birthday", DataType: "TEXT", Legend: "Edad", Input: dateAge,},
			
            {Name: "patient_contact", DataType: "TEXT", Legend: "No Teléfono", Input: phoneNumber, SkipCompletionAllowed: true,Render: true},
			
            {Name: "patient_gender", DataType: "TEXT", Legend: "Genero", Input: radioGenero, SkipValidation: true},
			
            {Name: "patient_address", DataType: "TEXT", Legend: "Dirección", Input: textPointArea},
		},
	}

	return &t
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Build added in v0.0.5

type Build interface {
	HtmlTAG(id, field_name string, skip_completion_allowed bool) string //construir vista usuario input
}

type Component

type Component struct {
	//ej: search_footer,datalist,form
	Name string
	// CssG() string | Css Global ej: .mi-style{background:black;}
	CssGlobal
	// CssP() string | Css Privado
	CssPrivate
	// JsG() string | Js Global
	JsGlobal
	// JsP() string | Js Privado Modulo ej: MyFunction(e){console.log("hello ",e)};
	JsPrivate
	// JsL() string | ej: btn.addEventListener('click', MyFunction);
	JsListeners
}

type CssGlobal added in v0.0.7

type CssGlobal interface {
	CssG() string
}

type CssPrivate added in v0.0.5

type CssPrivate interface {
	CssP() string
}

type Field

type Field struct {
	// si el campo comienza com id_ se considera como único y perteneciente a una tabla específica ej: id_user su tabla es user
	// otros ej: id_usuario, apellido, address, city etc
	Name        string
	Unique      bool   //campo único en db
	Inalterable bool   //la data en el campo sera inalterable después de la creación (¡no se puede modificar!)
	Legend      string //como se mostrara al usuario el campo en el encabezado ej: "name" por "Nombre Usuario"
	Input
	SkipValidation        bool //sin validar
	SkipCompletionAllowed bool //si el campo es requerido obligatoriamente o no

	NotRenderHtml bool // si no se necesita en formulario html

}

type Input added in v0.0.5

type Input struct {
	Component

	Build
	Validate

	TestData
}

type JsGlobal added in v0.0.5

type JsGlobal interface {
	JsG() string
}

type JsListeners added in v0.0.5

type JsListeners interface {
	JsL() string
}

type JsPrivate added in v0.0.7

type JsPrivate interface {
	JsP() string
}

type Module

type Module struct {
	//nombre modulo ej: chat,patient,user
	Name string
	//Titulo que vera el usuario ej: "Modulo Fotografía"
	Title string
	// icono según sprite svg ej: "icon-camera"
	Icon string
	//areas soportadas por el modulo ej: 'a','t','x'
	Areas []byte
	// ui/components que usa el modulo ej: form,datalist,search....
	Components []Component
	// objetos que contiene el modulo ej: patient,user
	Objects []Object
}

type Object

type Object struct {
	Name           string   //nombre del objeto o tabla
	TextFieldNames []string //nombre de campos mas representativos del objeto o tabla ej: nombre, apellido
	Fields         []Field  //campos del objeto
	//operaciones permitidas según nivel de acceso ej: 0,1,2,3,4 + Create bool, Update bool, Delete bool
	OperationsAllowed map[uint8]Permission
}

func (*Object) Columns

func (o *Object) Columns() (columns []string)

func (*Object) FilterField

func (o *Object) FilterField(nameRequired string) (fielsOut Field)

func (*Object) FilterFields

func (o *Object) FilterFields(namesRequired ...string) (fielsOut []Field)

func (*Object) FilterRemoveFields

func (o *Object) FilterRemoveFields(namesToRemove ...string) (fielsOut []Field)

func (*Object) GetFieldByName

func (o *Object) GetFieldByName(nameRq string) (fielOut Field)

func (*Object) GetID

func (o *Object) GetID(data_search map[string]string) string

func (*Object) GetRepresentativeTextField

func (o *Object) GetRepresentativeTextField(data_element map[string]string) (values string)

func (*Object) MainName

func (o *Object) MainName() string

func (*Object) PrimaryKeyName

func (o *Object) PrimaryKeyName() string

func (*Object) RenderFields

func (o *Object) RenderFields() (fielsOut []Field)

func (*Object) RequiredFields

func (o *Object) RequiredFields() (fielsOut []Field)

type Permission

type Permission struct {
	Create bool
	Update bool
	Delete bool
}

type Request

type Request struct {
	//usuario que ejecuta la solicitud
	*User
	// paquetes de solicitud y respuesta
	Packages []*Response
}

type Response

type Response struct {
	Type    string              `json:"t,omitempty"` //tipo solicitud respuesta: create, read, update, delete o error
	Object  string              `json:"o,omitempty"` //nombre de la tabla u objeto controlador hacia donde va la solicitud
	Module  string              `json:"m,omitempty"` //nombre del module controlador hacia donde va la solicitud
	Message string              `json:"g,omitempty"` //mensaje para el usuario de la solicitud
	Data    []map[string]string `json:"d,omitempty"` //data entrada y respuesta json

	SkipMeInResponse bool     `json:"-"` //  saltarme al difundir
	Recipients       []string `json:"-"` // lista de ip, token o ids según app para el reenvió al finalizar solicitud
	TargetArea       bool     `json:"-"` // si es falso el destino por defecto es publico de lo contrario sera para todos quines tengan la misma area del usuario solicitante
}

type TestData added in v0.0.10

type TestData interface {
	Good(table_name, field_name string, random bool) (out []string)
	WrongTestData() (out []string)
}

type User

type User struct {
	Token          string // token de sesión solicitante
	Ip             string
	Name           string
	Area           byte  //0 sin area.. un que byte y uint8 son lo mismo en go la idea que aca sea un valor de carácter ej: a,s,p...
	AccessLevel    uint8 // aquí valor numérico 0 a 255
	Packages       chan []*Response
	LastConnection time.Time
}

type Validate added in v0.0.5

type Validate interface {
	DataField(data_in string, skip_validation bool) bool //como sera validado
}

Jump to

Keyboard shortcuts

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