Tuesday, November 24, 2020

Belajar Golang #03 - Membuat Simple Web dengan Golang

https://play-lh.googleusercontent.com/edQ8_8or0qX3JymcLz5jrHskKXLGjj7b7lGYuBW-oUMmK75vspumKniy6gukdOuzbcNl=s180

 

main.go

package main

 

import (

  "fmt"

  "log"

  "net/http"

)

 

func index(w http.ResponseWriter, r *http.Request) {

  fmt.Fprintf(w, "Selamat Datang di belajaitjamannow.blogspot.com")

}

 

func about(w http.ResponseWriter, r *http.Request) {

  fmt.Fprintf(w, "Ini halaman About")

}


 

func main() {

  http.HandleFunc("/", index)

  http.HandleFunc("/about", about)

 

  log.Println("application started at port :8000")

  log.Fatal(http.ListenAndServe(":8000", nil))

}


Menjalankan program:

# go run main.go

 Buka Browser : http://localhost:8000

 Buka Browser : http://localhost:8000/about

No comments:

Post a Comment

Membuat Counter mundur menuju Azan dengan Arduino Wemos

Membuat Counter Mundur Menuju Azan dengan Arduino Wemos  #include <Wire.h> #include "RTClib.h" #include "SPI.h" #i...