examples

command
v0.0.0-...-a1c84da Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2021 License: MIT Imports: 15 Imported by: 0

README

Understanding templates

A template allows us to create one document and then merge data with it.

We are learning about templates so that we can create one document, a web page, and then merge customized data to that page.

Web templates allow us to serve personalized results to users.

Think of Facebook - you log into your main page and see results tailored for you. That main page was created once. It is a template. However, for each user, that template gets populated with data specific to that user.

Another common exposure to templates that most of us get every day - junk mail.

A company creates a piece of mail to send to everyone, and then they merge data with that template to customize the mailing for each individual. The result:

Template Example - Merged With Data


Dear Mr. Jones,

Are you tired of high electric bills?

We have noticed that your house at .....


Dear Mr. Smith,

Are you tired of high electric bills?

We have noticed that your house at .....


Template Example - The Template

Dear {{Name}},

Are you tired of high electric bills?

We have noticed that your house at .....

Documentation

Overview

What is Type Assertion?

As the name suggests they are used to assert that a variable is of some type.

Type assertions are used to check if the value held by the interface type variable either implements the desired interface (satisfies) or is of a concrete type.

They can only take place on interfaces.

Type assertions are performed at runtime.

x.(T) T is a concrete type or interface One (asserted value) or two (ok) values can be returned

Why would I use one? What exactly do they return?

x.(T) assert that x is not nil and that the value stored in x is type of T

Why would I use them?

  • to check that x is nil
  • to check if it is convertible (assert) to another type
  • convert (assert) it to another type

What exactly do they return?

t := x.(T) => is of type T; if x is nil, it panics
t, ok := x.(t) => if x is nil or not of type T => ok is false otherwise ok is true and t is of type T

vs. Type Conversion

Guess Game

  1. Generate a random number from 1 to 100, store it as a target number for the player to guess.
  2. Prompt the player to guess what the target number is, storing their response.
  3. If the guess is less than the target, return "Your guess is too LOW." If the player's guess is greater than the target number, return, "Your guess is too HIGH."
  4. Allow the player to guess up to 10 times. Before each guess, let the player know how many guesses they have left.
  5. If the player's guess is equal to the target number, return "Your guess is correct!" and stop asking for guesses.
  6. If the player ran out of turns without correctly guessing the target number, return, "Sorry, your attempts were unsuccessful. It was [X]" and return the target number.

Directories

Path Synopsis
design-patterns
examples
Exercise: 1.
Exercise: 1.
functions
Print the size of a file.
Print the size of a file.
types
Exercise: 1.
Exercise: 1.
types/numbers
Go-Pherit: A Learning Experience and personal SDK in Golang Copyright (c) 2020 Rye Miller https://darksociety.io
Go-Pherit: A Learning Experience and personal SDK in Golang Copyright (c) 2020 Rye Miller https://darksociety.io
Golph Calculates the average of several numbers.
Golph Calculates the average of several numbers.

Jump to

Keyboard shortcuts

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