Skip to content

Instantly share code, notes, and snippets.

View IndianGuru's full-sized avatar

IndianGuru IndianGuru

View GitHub Profile
{{ define "content" }}
<h1 style="color: red;">Hello World!</h1>
{{ end }}
> curl -i http://127.0.0.1:8080/process
HTTP/1.1 200 OK
Date: Sun, 08 Feb 2015 14:09:15 GMT
Content-Length: 187
Content-Type: text/html; charset=utf-8
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Go Web Programming</title>
@IndianGuru
IndianGuru / a.go
Created January 19, 2016 04:07
Using explicitly defined templates
func process(w http.ResponseWriter, r *http.Request) {
t, _ := template.ParseFiles("layout.html")
t.ExecuteTemplate(w, "layout", "")
}
@IndianGuru
IndianGuru / newlayout.html
Created January 19, 2016 04:05
Defining multiple templates in a single template file
{{ define "layout" }}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Go Web Programming</title>
</head>
<body>
{{ template "content" }}
</body>
</html>
@IndianGuru
IndianGuru / layout.html
Created January 19, 2016 04:02
Defining a template explicitly
{{ define "layout" }}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Go Web Programming</title>
</head>
<body>
{{ template "content" }}
</body>
</html>
@IndianGuru
IndianGuru / a.html
Created January 19, 2016 03:57
An unworkable layout file
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Go Web Programming</title>
</head>
<body>
{{ template "content.html" }}
</body>
</html>
@IndianGuru
IndianGuru / currencylayer.go
Created October 5, 2015 04:51
currencylayer.go
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
type Currencylayer struct {
@IndianGuru
IndianGuru / struct.go
Created October 5, 2015 04:19
struct.go
type Currencylayer struct {
Success bool `json:"success"`
Terms string `json:"terms"`
Privacy string `json:"privacy"`
Timestamp int `json:"timestamp"`
Source string `json:"source"`
Quotes struct {
Usdeur float64 `json:"USDEUR"`
Usdinr float64 `json:"USDINR"`
} `json:"quotes"`
@IndianGuru
IndianGuru / numverify.go
Last active October 25, 2020 19:56
numverify.go
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"net/url"
)
@IndianGuru
IndianGuru / type.go
Last active October 29, 2016 05:44
type.go
type Numverify struct {
Valid bool `json:"valid"`
Number string `json:"number"`
LocalFormat string `json:"local_format"`
InternationalFormat string `json:"international_format"`
CountryPrefix string `json:"country_prefix"`
CountryCode string `json:"country_code"`
CountryName string `json:"country_name"`
Location string `json:"location"`
Carrier string `json:"carrier"`