Welcome to GoTermux documentation. GoTermux is a wrapper around termux-api CMD scripts.

Convention #

Function names in GoTermux follow the same naming style as Termux API commands, but without dashes (-):

GoTermux #

gotermux.TermuxBatteryStatus()

Termux API #

~/ $ termux-battery-status

Quickstart #

First of all, you need to install termux-api package:

pkg install termux-api

And also Go:

pkg install golang

And let’s create an example folder inside of ~/go/src/, then init a go module:

mkdir -r ~/go/src/example
cd ~/go/src/example
go mod init

Then we need to download GoTermux library:

go get github.com/hugmouse/gotermux

And now we can finally use it. Create main.go inside of ~/go/src/example/ folder and put the following code in there:

package main

import (
    "fmt"
    "github.com/hugmouse/gotermux"
)

func main() {
    fmt.Println(gotermux.TermuxBatteryStatus()) 
}
This code will print the following: {GOOD 77 UNPLUGGED DISCHARGING 22.8}

And then you can execute it using go run main.go.