Notes
![]() ![]() Notes - notes.io |
package main
import (
"html/template"
"net/http"
)
type ContactDetails struct {
Email string
Subject string
Message string
}
func main() {
tmpl := template.Must(template.ParseFiles("forms.html"))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request)
{
if r.Method != http.MethodPost {
tmpl.Execute(w, nil)
return
}
details := ContactDetails{
Email: r.FormValue("email"),
Subject: r.FormValue("subject"),
Message: r.FormValue("message"),
}
// do something with details
_ = details
tmpl.Execute(w, struct{ Success bool }{true})
})
http.ListenAndServe(":8080", nil)
}
<!-- forms.html -->
{{if .Success}}
<h1>Thanks for your message!</h1>
{{else}}
<h1>Contact</h1>
<form method="POST">
<label>Email:</label><br />
<input type="text" name="email"><br />
<label>Subject:</label><br />
<input type="text" name="subject"><br />
<label>Message:</label><br />
<textarea name="message"></textarea><br />
<input type="submit">
</form>
{{end}}
Exp-9
package main
import "fmt"
func main(){
var num[100] int
var temp,sum,avg int
fmt.Print("Enter number of elements: ")
fmt.Scanln(&temp)
for i := 0; i < temp; i++ {
fmt.Print("Enter the number : ")
fmt.Scanln(&num[i])
sum += num[i]
}
avg = sum/temp
fmt.Printf("The Average of entered %d number(s) is
%d",temp,avg)
}
Exp-10
package main
import "fmt"
// function to remove duplicate values
func removeDuplicates(s []string) []string {
bucket := make(map[string]bool)
var result []string
for _, str := range s {
if _, ok := bucket[str]; !ok {
bucket[str] = true
result = append(result, str)
}
}
return result
}
func main() {
// creating an array of strings
array := []string{"abc", "cde", "efg", "efg", "abc", "cde"}
fmt.Println("The given array of string is:", array)
fmt.Println()
// calling the function
result := removeDuplicates(array)
fmt.Println("The array obtained after removing the duplicate entries is:", result)
}
Exp 11
package main
import (
"fmt"
"sort"
)
func main() {
fmt.Println("Interger Reverse Sort")
num := []int{50,90, 30, 10, 50}
sort.Sort(sort.Reverse(sort.IntSlice(num)))
fmt.Println(num)
fmt.Println()
fmt.Println("String Reverse Sort")
text := []string{"Japan","UK","Germany","Australia","Pakistan"}
sort.Sort(sort.Reverse(sort.StringSlice(text)))
fmt.Println(text)
}
Exp12
Package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.ContainsAny("Germany", "G"))
fmt.Println(strings.ContainsAny("Germany", "g"))
fmt.Println(strings.Contains("Germany", "Ger"))
fmt.Println(strings.Contains("Germany", "ger"))
fmt.Println(strings.Contains("Germany", "er"))
fmt.Println(strings.Count("cheese", "e"))
fmt.Println(strings.EqualFold("Cat", "cAt"))
fmt.Println(strings.EqualFold("India", "Indiana"))
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team