Golang net/http.Dir type and Dir.Open() function example

package net/http

Golang net/http.Dir type and Dir.Open() function usage example

 package main

 import (
 "fmt"
 "net/http"
 )

 func main() {

 var directory http.Dir

 directory = "./" 

 file, err := directory.Open("input.txt")

 if err != nil {
 panic(file)
 }

 fileInfo, _ := file.Stat()

 fmt.Println(fileInfo.Name())
 fmt.Println("Size : ", fileInfo.Size())
 }

Output :

input.txt

Size : 22

References :

http://golang.org/pkg/net/http/#Dir

http://golang.org/pkg/net/http/#Dir.Open

Advertisement