index work
This commit is contained in:
parent
997fcafeca
commit
e4b083d49b
@ -1,21 +0,0 @@
|
|||||||
// ## File Open
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import "os"
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
file, err := os.Open("xx-file-open.go")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
stat, err := file.Stat()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("Program has", stat.Size(), "bytes")
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
// ## File Read
|
// ## Reading files
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
@ -12,3 +12,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
fmt.Print(string(contents))
|
fmt.Print(string(contents))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// todo: streaming reads
|
@ -1,4 +1,4 @@
|
|||||||
// ## File Write
|
// ## Writing Files
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
@ -12,3 +12,5 @@ func main() {
|
|||||||
defer file.Close()
|
defer file.Close()
|
||||||
file.WriteString("contents\n")
|
file.WriteString("contents\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: streaming writes
|
@ -1,4 +1,4 @@
|
|||||||
// ## Env
|
// ## Environment Variables
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
6
060-environment-variables/environment-variables.sh
Normal file
6
060-environment-variables/environment-variables.sh
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
$ go run environment-variables.go
|
||||||
|
HOME
|
||||||
|
PATH
|
||||||
|
PWD
|
||||||
|
...
|
||||||
|
bar
|
@ -1,6 +0,0 @@
|
|||||||
$ go run env.go
|
|
||||||
HOME
|
|
||||||
PATH
|
|
||||||
PWD
|
|
||||||
...
|
|
||||||
bar
|
|
@ -1,8 +1,9 @@
|
|||||||
// ## Spawn
|
// ## Spawning Processes
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import ("os/exec"; "fmt")
|
import "os/exec"
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cmd := exec.Command("ls", "-a", "-l")
|
cmd := exec.Command("ls", "-a", "-l")
|
@ -1,6 +1,6 @@
|
|||||||
$ go run spawn.go
|
$ go run spawning-processes.go
|
||||||
Files:
|
Files:
|
||||||
total 8
|
total 8
|
||||||
drwxr-xr-x 3 mmcgrana staff 102 Sep 23 11:35 .
|
drwxr-xr-x 3 mmcgrana staff 102 Sep 23 11:35 .
|
||||||
drwxr-xr-x 101 mmcgrana staff 3434 Sep 23 11:25 ..
|
drwxr-xr-x 101 mmcgrana staff 3434 Sep 23 11:25 ..
|
||||||
-rw-r--r--@ 1 mmcgrana staff 241 Sep 23 11:37 spawn.go
|
-rw-r--r--@ 1 mmcgrana staff 241 Sep 23 11:37 spawning-processes.go
|
@ -1,4 +1,4 @@
|
|||||||
// ## Exec
|
// ## Exec'ing Processes
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
@ -16,3 +16,5 @@ func main() {
|
|||||||
panic(execErr)
|
panic(execErr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: note lack of fork
|
@ -18,3 +18,5 @@ func main() {
|
|||||||
fmt.Println("Awaiting signal")
|
fmt.Println("Awaiting signal")
|
||||||
<- d
|
<- d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: sending signals?
|
@ -1,11 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
import "os/user"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
me, _ := user.Current()
|
|
||||||
fmt.Println(me)
|
|
||||||
root, _ := user.Lookup("root")
|
|
||||||
fmt.Println(root)
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
$ go run users.go
|
|
||||||
&{501 20 mmcgrana Mark McGranaghan /Users/mmcgrana}
|
|
||||||
&{0 0 root System Administrator /var/root}
|
|
@ -70,18 +70,17 @@ sha1-hashes
|
|||||||
~ base64-encoding
|
~ base64-encoding
|
||||||
|
|
||||||
# systems programming
|
# systems programming
|
||||||
file-open
|
reading-files
|
||||||
file-read
|
writing-files
|
||||||
file-write
|
~ standard-streams
|
||||||
command-line-arguments
|
command-line-arguments
|
||||||
command-line-flags
|
command-line-flags
|
||||||
env
|
environment-variables
|
||||||
|
spawning-processes
|
||||||
|
execing-processes
|
||||||
signals
|
signals
|
||||||
exit
|
exit
|
||||||
spawn
|
|
||||||
exec
|
|
||||||
reading-input
|
reading-input
|
||||||
users
|
|
||||||
line-filter
|
line-filter
|
||||||
tcp server
|
tcp server
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user