-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from bb4L/feat/v1
V1
- Loading branch information
Showing
15 changed files
with
733 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.154.0/containers/go/.devcontainer/base.Dockerfile | ||
|
||
# [Choice] Go version: 1, 1.15, 1.14 | ||
ARG VARIANT="1" | ||
FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT} | ||
|
||
# [Option] Install Node.js | ||
ARG INSTALL_NODE="true" | ||
ARG NODE_VERSION="lts/*" | ||
RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi | ||
|
||
# [Optional] Uncomment this section to install additional OS packages. | ||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ | ||
# && apt-get -y install --no-install-recommends <your-package-list-here> | ||
|
||
# [Optional] Uncomment the next line to use go get to install anything else you need | ||
# RUN go get -x <your-dependency-or-tool> | ||
|
||
# [Optional] Uncomment this line to install global node packages. | ||
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: | ||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.154.0/containers/go | ||
{ | ||
"name": "Go", | ||
"build": { | ||
"dockerfile": "Dockerfile", | ||
"args": { | ||
// Update the VARIANT arg to pick a version of Go: 1, 1.15, 1.14 | ||
"VARIANT": "1.15", | ||
// Options | ||
"INSTALL_NODE": "false", | ||
"NODE_VERSION": "lts/*" | ||
} | ||
}, | ||
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], | ||
|
||
// Set *default* container specific settings.json values on container create. | ||
"settings": { | ||
"terminal.integrated.shell.linux": "/bin/bash", | ||
"go.useGoProxyToCheckForToolUpdates": false, | ||
"go.useLanguageServer": true, | ||
"go.gopath": "/go", | ||
"go.goroot": "/usr/local/go", | ||
"go.toolsGopath": "/go/bin" | ||
}, | ||
|
||
// Add the IDs of extensions you want installed when the container is created. | ||
"extensions": [ | ||
"golang.Go" | ||
], | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
|
||
// Use 'postCreateCommand' to run commands after the container is created. | ||
// "postCreateCommand": "go version", | ||
|
||
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. | ||
"remoteUser": "vscode" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.15 | ||
|
||
- name: Build linux arm | ||
run: env GOOS=linux GOARCH=arm go build -o build/rpi_radio_alarm_arm | ||
|
||
- name: Build linux 64 | ||
run: env GOOS=linux GOARCH=amd64 go build -o build/rpi_radio_alarm_64 | ||
|
||
- name: Upload Binaries | ||
uses: actions/upload-artifact@v1 | ||
with: | ||
name: bins | ||
path: build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,16 @@ | ||
# rpi-radio-alarm-go | ||
Go implementation of the rpi-radio-alarm | ||
# rpi-radio-alarm-go ![CI](https://github.com/bb4L/rpi-radio-alarm-go/workflows/CI/badge.svg) | ||
Go implementation of a radio alarm clock. | ||
|
||
This project is ment to be run on a raspberry pi. | ||
|
||
It **should** be compatible to the tools for the [original implementation](https://github.com/bb4L/rpi-radio-alarm) | ||
|
||
## Requirements | ||
Ensure that you have `mplayer` installed. ( `apt install mplayer`) | ||
[mplayer](http://www.mplayerhq.hu/) is used to play the web radio. | ||
|
||
## Android app | ||
a android native app can be found [here](https://github.com/bb4L/rpi-radio-alarm-android-native) | ||
|
||
# License | ||
[GPLv3](LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module rpi-radio-alarm | ||
|
||
go 1.15 | ||
|
||
require github.com/gorilla/mux v1.8.0 | ||
require gopkg.in/yaml.v2 v2.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= | ||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= | ||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package storage | ||
|
||
import ( | ||
"io/ioutil" | ||
"rpi-radio-alarm/logging" | ||
alarmtypes "rpi-radio-alarm/resources/types" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
// Settings contains specific settings for the program | ||
type Settings struct { | ||
Port int `yaml:"port"` | ||
} | ||
|
||
// RpiRadioAlarmData contains all the data for the RpiRadioAlarm | ||
type RpiRadioAlarmData struct { | ||
Settings Settings `yaml:"settings"` | ||
Alarms []alarmtypes.Alarm `yaml:"alarms"` | ||
Radio alarmtypes.Radio `yaml:"radio"` | ||
} | ||
|
||
const dataFilename = "./rpi_data.yaml" | ||
|
||
// GetStoredData returns the whole data | ||
func GetStoredData() (RpiRadioAlarmData, error) { | ||
fileData, err := ioutil.ReadFile(dataFilename) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
var data RpiRadioAlarmData | ||
|
||
source := []byte(fileData) | ||
err = yaml.Unmarshal(source, &data) | ||
if err != nil { | ||
logging.GetFatalLogger().Fatalf("error: %v", err) | ||
} | ||
return data, err | ||
} | ||
|
||
// SaveData save the data to the file | ||
func SaveData(data RpiRadioAlarmData) { | ||
outSource, err := yaml.Marshal(data) | ||
if err != nil { | ||
logging.GetFatalLogger().Fatalf("error: %v", err) | ||
} | ||
|
||
ioutil.WriteFile(dataFilename, outSource, 0777) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package logging | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"sync" | ||
) | ||
|
||
var ( | ||
// InfoLogger logging info | ||
InfoLogger *log.Logger | ||
|
||
// ErrorLogger logging errors | ||
ErrorLogger *log.Logger | ||
|
||
// FatalLogger logging fatal | ||
FatalLogger *log.Logger | ||
|
||
once sync.Once | ||
) | ||
|
||
// GetInfoLogger returns the InfoLogger | ||
func GetInfoLogger() *log.Logger { | ||
return log.New(os.Stderr, "INFO: ", log.Ldate|log.Ltime|log.Lmsgprefix) | ||
} | ||
|
||
// GetErrorLogger returns the ErrorLogger | ||
func GetErrorLogger() *log.Logger { | ||
return log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lmsgprefix) | ||
} | ||
|
||
// GetFatalLogger returns the FatalLogger | ||
func GetFatalLogger() *log.Logger { | ||
return log.New(os.Stderr, "FATAL: ", log.Ldate|log.Ltime|log.Lmsgprefix) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
storage "rpi-radio-alarm/helper" | ||
"rpi-radio-alarm/logging" | ||
"rpi-radio-alarm/resources/alarm" | ||
"rpi-radio-alarm/resources/radio" | ||
"rpi-radio-alarm/runner" | ||
"strconv" | ||
|
||
"github.com/gorilla/mux" | ||
) | ||
|
||
func health(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
w.Write([]byte(`{"status": "healthy"}`)) | ||
} | ||
|
||
func main() { | ||
go runner.Runner() | ||
|
||
r := mux.NewRouter() | ||
r.HandleFunc("/health", health).Methods(http.MethodGet) | ||
|
||
alarm.SetUpRouter(r.PathPrefix("/alarm").Subrouter()) | ||
radio.SetUpRouter(r.PathPrefix("/radio").Subrouter()) | ||
|
||
storedData, err := storage.GetStoredData() | ||
if err != nil { | ||
logging.GetFatalLogger().Fatalln("error on getting stored data") | ||
} | ||
|
||
port := strconv.Itoa(storedData.Settings.Port) | ||
logging.GetInfoLogger().Printf("starting server on port %s", port) | ||
log.Fatal(http.ListenAndServe(":"+port, r)) | ||
} |
Oops, something went wrong.