tmpl

package
v0.0.0-...-9f76edf Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package tmpl provides methods primarily used in html templates.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolSelectbox

func BoolSelectbox(selected *bool, name string) template.HTML

BoolSelectbox returns selectbox html text which including `true`, `false` and `undefined`, with a specified name.

selected argument specifies a option selected by default and if selected is nil, undefined should be selected by default.

func Checkbox

func Checkbox(checked bool, name string) template.HTML

Checkbox returns checkbox html text with a specified name. If checked is true, generated checkbox is checked by default.

func GetBoolSelectboxValue

func GetBoolSelectboxValue(val map[string][]string, index int, name string) *bool

GetBoolSelectboxValue returns a boolean pointer from specified arguments, in which val is html form values a user sent.

This method has one-to-one relationship with BoolSelectBox and if the user selected `undefined`, this should return nil.

func GetFloat64Ptr

func GetFloat64Ptr(val map[string][]string, index int, name string) (*float64, error)

GetFloat64Ptr returns a float pointer from corresponding user textbox input.

If the textbox is empty, this returns nil. If the user input is invalid, this returns an error.

func GetIntPtr

func GetIntPtr(val map[string][]string, index int, name string) (*int, error)

GetIntPtr returns an integer pointer from corresponding user textbox input.

If the textbox is empty, this returns nil. If the user input is invalid, this returns an error.

func GetLikelihood

func GetLikelihood(r *http.Request, name string, index int, def string) string

func GetListTextboxValue

func GetListTextboxValue(val map[string][]string, index int, name string) []string

GetListTextboxValue returns a string slice a user inputted into the corresponding list textbox.

val argument is html form values the user sent.

func GetString

func GetString(val map[string][]string, name string, index int, def string) string

GetString just returns a string value from specified user html form input.

If there is no value corresponded to specified name and index, this returns def.

func LikelihoodMultiSelect

func LikelihoodMultiSelect(val string, name string, index int) template.HTML

func ListTextbox

func ListTextbox(list []string, name, class string) template.HTML

ListTextbox returns html text with specified initial list values and name.

func NewMap

func NewMap(objs ...interface{}) map[string]interface{}

NewMap returns a map instance with specified arguments.

This goes into panic if the order of objs is not key-value one.

Example
package main

import (
	"fmt"
	"github.com/iwataka/mybot/tmpl"
)

func main() {
	m := tmpl.NewMap("key1", "val", "key2", 1)
	fmt.Println(m["key1"])
	fmt.Println(m["key2"])
}
Output:

val
1

func Selectbox

func Selectbox(str, name string, opts ...string) template.HTML

Selectbox returns selectbox html text with specified name and options. str argument specifies default selected value in this selectbox.

func TextboxOfFloat64Ptr

func TextboxOfFloat64Ptr(val *float64, name string) template.HTML

TextboxOfFloat64Ptr returns html textbox text with an initial value and name.

If val is nil, generated textbox has no default value.

func TextboxOfIntPtr

func TextboxOfIntPtr(val *int, name string) template.HTML

TextboxOfIntPtr returns html textbox text with specified initial value and name.

If val is nil, generated textbox has no default value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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