├── Procfile ├── static ├── assets │ ├── pwa │ │ ├── banner.png │ │ ├── favicon.ico │ │ ├── favicon-16x16.png │ │ ├── favicon-32x32.png │ │ ├── apple-touch-icon.png │ │ ├── android-chrome-192x192.png │ │ ├── android-chrome-512x512.png │ │ └── manifest.json │ └── icons │ │ ├── api-docs.svg │ │ ├── github.svg │ │ └── loader.svg ├── script.js ├── styles.css └── index.html ├── yarn.lock ├── .gitignore ├── go.mod ├── vercel.json ├── Dockerfile ├── go.sum ├── app.json ├── docker-compose.yml ├── .github ├── workflows │ ├── compile-releases.yml │ └── docker-build-publish.yml ├── CODE_OF_CONDUCT.md └── README.md ├── api ├── image.go └── apod.go ├── LICENSE ├── shared └── shared.go └── main.go /Procfile: -------------------------------------------------------------------------------- 1 | web: go-apod 2 | -------------------------------------------------------------------------------- /static/assets/pwa/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lissy93/go-apod/HEAD/static/assets/pwa/banner.png -------------------------------------------------------------------------------- /static/assets/pwa/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lissy93/go-apod/HEAD/static/assets/pwa/favicon.ico -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | -------------------------------------------------------------------------------- /static/assets/pwa/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lissy93/go-apod/HEAD/static/assets/pwa/favicon-16x16.png -------------------------------------------------------------------------------- /static/assets/pwa/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lissy93/go-apod/HEAD/static/assets/pwa/favicon-32x32.png -------------------------------------------------------------------------------- /static/assets/pwa/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lissy93/go-apod/HEAD/static/assets/pwa/apple-touch-icon.png -------------------------------------------------------------------------------- /static/assets/pwa/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lissy93/go-apod/HEAD/static/assets/pwa/android-chrome-192x192.png -------------------------------------------------------------------------------- /static/assets/pwa/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lissy93/go-apod/HEAD/static/assets/pwa/android-chrome-512x512.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | bin/ 3 | .env 4 | 5 | *.exe 6 | *.exe~ 7 | *.dll 8 | *.so 9 | *.dylib 10 | go.work 11 | 12 | .vercel 13 | 14 | node_modules/ 15 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/lissy93/go-apod 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/go-chi/chi/v5 v5.0.7 7 | github.com/go-chi/cors v1.2.1 8 | github.com/kelseyhightower/envconfig v1.4.0 9 | ) 10 | -------------------------------------------------------------------------------- /vercel.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "builds": [ 4 | { 5 | "src": "/api/*.go", 6 | "use": "@vercel/go" 7 | }, 8 | { "src": "static/**", "use": "@vercel/static"} 9 | ], 10 | "rewrites": [ 11 | { "source": "/apod", "destination": "/api/apod.go" }, 12 | { "source": "/image", "destination": "/api/image.go" }, 13 | { "source": "/static/(.*)", "destination": "/static/$1" }, 14 | { "source": "/(.*)", "destination": "/static/$1" } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | 2 | FROM golang:1.18-alpine AS build 3 | # Adds argument for API key 4 | ARG NASA_API_KEY 5 | # Set working directory 6 | WORKDIR /app 7 | # Copy over all files 8 | COPY . . 9 | # Download Go modules 10 | RUN go mod download 11 | # Compile binaries 12 | RUN go build -o ./apod 13 | 14 | FROM alpine:latest 15 | RUN apk --no-cache add ca-certificates 16 | WORKDIR /app 17 | COPY --from=build /app/apod ./ 18 | # Specify internal port 19 | EXPOSE 8080 20 | # Run the built app! 21 | CMD [ "./apod" ] 22 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8= 2 | github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= 3 | github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4= 4 | github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58= 5 | github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= 6 | github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= 7 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Go-APOD", 3 | "description": "A CORS-enabled, no-auth wrapper to NASA's Astronomy Picture of the Day", 4 | "keywords": [ "NASA", "APOD", "API", "Go" ], 5 | "website": "https://apod.as93.net", 6 | "repository": "https://github.com/Lissy93/go-apod", 7 | "logo": "https://i.ibb.co/0fv7k6T/milky-way.png", 8 | "success_url": "/", 9 | "env": { 10 | "NASA_API_KEY": { 11 | "description": "Get your API key here: https://api.nasa.gov/", 12 | "required": true 13 | } 14 | }, 15 | "formation": { 16 | "web": { 17 | "quantity": 1, 18 | "size": "free" 19 | } 20 | }, 21 | "image": "heroku/go", 22 | "stack": "heroku-22" 23 | } 24 | -------------------------------------------------------------------------------- /static/assets/pwa/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Astronomy Picture of the Day", 3 | "short_name": "APOD", 4 | "description": "A CORS-enabled, no-auth wrapper to NASA's APOD API", 5 | "icons": [ 6 | { "src": "assets/pwa/android-chrome-192x192.png", "sizes": "192x192", "type": "image/png" }, 7 | { "src": "assets/pwa/android-chrome-512x512.png", "sizes": "512x512", "type": "image/png" }, 8 | { "src": "assets/pwa/apple-touch-icon.png", "sizes": "180x180", "type": "image/png" }, 9 | { "src": "assets/pwa/favicon-32x32.png", "sizes": "32x32", "type": "image/png" }, 10 | { "src": "assets/pwa/favicon-16x16.png", "sizes": "16x16", "type": "image/png" } 11 | ], 12 | "theme_color": "#8120F7", 13 | "background_color": "#2c2c2d", 14 | "display": "standalone" 15 | } 16 | -------------------------------------------------------------------------------- /static/assets/icons/api-docs.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /static/assets/icons/github.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Welcome to Go-APOD! To get started, run `docker compose up -d` 3 | # You can configure your container here, by modifying this file 4 | # See GH repo for more info: https://github.com/lissy93/go-apod 5 | # Licensed under MIT © Alicia Sykes 2022 6 | 7 | version: "3.8" 8 | services: 9 | apod: 10 | container_name: APOD 11 | 12 | # Pull latest image from DockerHub 13 | image: lissy93/apod 14 | 15 | # To build from source, replace 'image: lissy93/go-apod' with 'build: .' 16 | # build: . 17 | 18 | # Set port that the app will be served on. Keep second option, container port as 8080 19 | ports: 20 | - 8080:8080 21 | 22 | # Specify your API key, and any other env vars 23 | environment: 24 | - NASA_API_KEY='' 25 | # Specify your user ID and group ID. You can find this by running `id -u` and `id -g` 26 | # - UID=1000 27 | # - GID=1000 28 | 29 | # Specify restart policy 30 | restart: unless-stopped 31 | -------------------------------------------------------------------------------- /.github/workflows/compile-releases.yml: -------------------------------------------------------------------------------- 1 | name: 🛠️ Compile Release Assets 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | jobs: 8 | releases-matrix: 9 | name: Release Go Binary 10 | runs-on: ubuntu-latest 11 | strategy: 12 | matrix: 13 | # build and publish in parallel: linux/386, linux/amd64, linux/arm64, windows/386, windows/amd64, darwin/amd64, darwin/arm64 14 | goos: [linux, windows, darwin] 15 | goarch: ['386', amd64, arm64] 16 | exclude: 17 | - goarch: '386' 18 | goos: darwin 19 | - goarch: arm64 20 | goos: windows 21 | steps: 22 | - uses: actions/checkout@v3 23 | - uses: wangyoucao577/go-release-action@v1.29 24 | with: 25 | github_token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} 26 | goos: ${{ matrix.goos }} 27 | goarch: ${{ matrix.goarch }} 28 | goversion: 1.18 29 | project_path: '.' 30 | binary_name: go-apod 31 | md5sum: true 32 | extra_files: LICENSE 33 | -------------------------------------------------------------------------------- /api/image.go: -------------------------------------------------------------------------------- 1 | package handler 2 | 3 | import ( 4 | "io" 5 | "net/http" 6 | 7 | "github.com/lissy93/go-apod/shared" // Ensure this import path is correct 8 | ) 9 | 10 | func Handler(w http.ResponseWriter, r *http.Request) { 11 | conf, err := shared.NewConfig() 12 | if err != nil { 13 | http.Error(w, err.Error(), http.StatusInternalServerError) 14 | return 15 | } 16 | 17 | client := &http.Client{} 18 | apodData, err := shared.FetchApod(r.Context(), client, conf) 19 | if err != nil { 20 | http.Error(w, err.Error(), http.StatusInternalServerError) 21 | return 22 | } 23 | 24 | // Fetch the image from the URL in the APOD data 25 | imageResp, err := http.Get(apodData.Url) 26 | if err != nil { 27 | http.Error(w, err.Error(), http.StatusInternalServerError) 28 | return 29 | } 30 | defer imageResp.Body.Close() 31 | 32 | // Copy the content type and content from the response 33 | w.Header().Set("Content-Type", imageResp.Header.Get("Content-Type")) 34 | w.WriteHeader(imageResp.StatusCode) 35 | _, err = io.Copy(w, imageResp.Body) 36 | if err != nil { 37 | http.Error(w, err.Error(), http.StatusInternalServerError) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /api/apod.go: -------------------------------------------------------------------------------- 1 | package handler 2 | 3 | import ( 4 | "encoding/json" 5 | "net/http" 6 | "os" 7 | 8 | "github.com/lissy93/go-apod/shared" 9 | ) 10 | 11 | func Handler(w http.ResponseWriter, r *http.Request) { 12 | corsAllowedOrigins := os.Getenv("CORS_ALLOWED_ORIGINS") 13 | if corsAllowedOrigins == "" { 14 | corsAllowedOrigins = "*" // Default to allowing all origins 15 | } 16 | 17 | // Set CORS headers 18 | w.Header().Set("Access-Control-Allow-Origin", corsAllowedOrigins) 19 | w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS") 20 | w.Header().Set("Access-Control-Allow-Headers", "Content-Type") 21 | 22 | if r.Method == http.MethodOptions { 23 | return 24 | } 25 | 26 | conf, err := shared.NewConfig() 27 | if err != nil { 28 | http.Error(w, err.Error(), http.StatusInternalServerError) 29 | return 30 | } 31 | 32 | client := &http.Client{} 33 | apodResponse, err := shared.FetchApod(r.Context(), client, conf) 34 | if err != nil { 35 | http.Error(w, err.Error(), http.StatusInternalServerError) 36 | return 37 | } 38 | 39 | w.Header().Set("Content-Type", "application/json") 40 | json.NewEncoder(w).Encode(apodResponse) 41 | } 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Alicia Sykes 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /static/assets/icons/loader.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 13 | 21 | 22 | 23 | 31 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /shared/shared.go: -------------------------------------------------------------------------------- 1 | package shared 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "fmt" 7 | "net/http" 8 | 9 | "github.com/kelseyhightower/envconfig" 10 | ) 11 | 12 | type Config struct { 13 | Port string `envconfig:"PORT" default:"8080"` 14 | CORSAllowedOrigins string `envconfig:"CORS_ALLOWED_ORIGINS" default:"*"` 15 | NASAAPIKey string `envconfig:"NASA_API_KEY" required:"true"` 16 | NASABaseURL string `envconfig:"NASA_BASE_URL" default:"https://api.nasa.gov/planetary/apod"` 17 | } 18 | 19 | func NewConfig() (*Config, error) { 20 | var conf Config 21 | err := envconfig.Process("apod", &conf) 22 | if err != nil { 23 | return nil, err 24 | } 25 | return &conf, nil 26 | } 27 | 28 | type ApodResponse struct { 29 | Copyright string `json:"copyright,omitempty"` 30 | Date string `json:"date,omitempty"` 31 | Explanation string `json:"explanation,omitempty"` 32 | HdUrl string `json:"hdurl,omitempty"` 33 | MediaType string `json:"media_type,omitempty"` 34 | ServiceVersion string `json:"service_version,omitempty"` 35 | Title string `json:"title,omitempty"` 36 | Url string `json:"url,omitempty"` 37 | } 38 | 39 | func FetchApod(ctx context.Context, client *http.Client, conf *Config) (*ApodResponse, error) { 40 | url := fmt.Sprintf("%s?api_key=%s", conf.NASABaseURL, conf.NASAAPIKey) 41 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) 42 | if err != nil { 43 | return nil, err 44 | } 45 | 46 | resp, err := client.Do(req) 47 | if err != nil { 48 | return nil, err 49 | } 50 | defer resp.Body.Close() 51 | 52 | result := ApodResponse{} 53 | err = json.NewDecoder(resp.Body).Decode(&result) 54 | if err != nil { 55 | return nil, err 56 | } 57 | return &result, nil 58 | } 59 | -------------------------------------------------------------------------------- /.github/workflows/docker-build-publish.yml: -------------------------------------------------------------------------------- 1 | # Scans, builds and releases a multi-architecture docker image 2 | name: 🐳 Build + Publish Multi-Platform Image 3 | 4 | on: 5 | workflow_dispatch: 6 | push: 7 | branches: ['master'] 8 | tags: '*' 9 | release: 10 | types: [published] 11 | paths: 12 | - '**.go' 13 | - 'static/**' 14 | 15 | env: 16 | DH_IMAGE: lissy93/apod 17 | GH_IMAGE: ${{ github.repository_owner }}/${{ github.event.repository.name }} 18 | 19 | jobs: 20 | docker: 21 | runs-on: ubuntu-latest 22 | permissions: { contents: read, packages: write } 23 | if: "!contains(github.event.head_commit.message, '[ci-skip]')" 24 | 25 | steps: 26 | - name: 🛎️ Checkout Repo 27 | uses: actions/checkout@v2 28 | 29 | # - name: ✨ Validate Dockerfile 30 | # uses: ghe-actions/dockerfile-validator@v1 31 | # with: 32 | # dockerfile: 'Dockerfile' 33 | # lint: 'hadolint' 34 | 35 | - name: 🗂️ Make Docker Meta 36 | id: meta 37 | uses: docker/metadata-action@v3 38 | with: 39 | images: | 40 | ${{ env.DH_IMAGE }} 41 | ghcr.io/${{ env.GH_IMAGE }} 42 | tags: | 43 | type=raw,value=latest,enable={{is_default_branch}} 44 | type=ref,event=branch 45 | type=ref,event=tag 46 | labels: | 47 | maintainer=Lissy93 48 | org.opencontainers.image.title=APOD 49 | org.opencontainers.image.description=Astronomy Picture of the Day App and API 50 | org.opencontainers.image.documentation=https://apod.as93.net 51 | org.opencontainers.image.authors=Alicia Sykes 52 | org.opencontainers.image.licenses=MIT 53 | 54 | - name: 🔧 Set up QEMU 55 | uses: docker/setup-qemu-action@v1 56 | 57 | - name: 🔧 Set up Docker Buildx 58 | uses: docker/setup-buildx-action@v1 59 | 60 | - name: 🔑 Login to DockerHub 61 | uses: docker/login-action@v1 62 | with: 63 | username: ${{ secrets.DOCKER_USERNAME }} 64 | password: ${{ secrets.DOCKER_PASSWORD }} 65 | 66 | - name: 🔑 Login to GitHub Container Registry 67 | uses: docker/login-action@v1 68 | with: 69 | registry: ghcr.io 70 | username: ${{ github.repository_owner }} 71 | password: ${{ secrets.GITHUB_TOKEN }} 72 | 73 | # - name: 🔑 Login to Azure Container Registry 74 | # uses: docker/login-action@v1 75 | # with: 76 | # registry: ${{ secrets.ACR_SERVER }} 77 | # username: ${{ secrets.ACR_USERNAME }} 78 | # password: ${{ secrets.ACR_PASSWORD }} 79 | 80 | - name: 🚦 Check Registry Status 81 | uses: crazy-max/ghaction-docker-status@v1 82 | 83 | - name: ⚒️ Build and push 84 | uses: docker/build-push-action@v2 85 | with: 86 | context: . 87 | file: ./Dockerfile 88 | platforms: linux/amd64,linux/arm64,linux/arm/v7 89 | tags: ${{ steps.meta.outputs.tags }} 90 | labels: ${{ steps.meta.outputs.labels }} 91 | push: true 92 | 93 | # - name: 💬 Set Docker Hub Description 94 | # uses: peter-evans/dockerhub-description@v2 95 | # with: 96 | # repository: lissy93/dashy 97 | # readme-filepath: ./docker/docker-readme.md 98 | # short-description: Dashy - A self-hosted start page for your server 99 | # username: ${{ secrets.DOCKER_USERNAME }} 100 | # password: ${{ secrets.DOCKER_USER_PASS }} 101 | 102 | -------------------------------------------------------------------------------- /static/script.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Vanilla JS code for the homepage. 3 | * Fetches todays image and meta info from backend, and renders to UI 4 | */ 5 | 6 | /* API endpoint paths, using either current server or public instance */ 7 | const makeEndpointUrls = () => { 8 | const origin = window.location.origin; 9 | const hostname = origin && origin !== 'null' ? origin : 'https://go-apod.herokuapp.com'; 10 | return { 11 | home: hostname, 12 | apod: `${hostname}/apod`, 13 | image: `${hostname}/image`, 14 | }; 15 | }; 16 | 17 | /* Fetch data from APOD API */ 18 | const makeRequest = () => { 19 | const apiUrl = makeEndpointUrls().apod; 20 | fetch(apiUrl) 21 | .then(response => response.json()) 22 | .then(data => { 23 | updateDom(data); 24 | }) 25 | .catch((error) => { 26 | showError(error); 27 | }).finally(() => { 28 | hideLoader(); 29 | }); 30 | } 31 | 32 | /* Hide loading spinner */ 33 | const hideLoader = () => { 34 | document.getElementById('loader').style.display = 'none'; 35 | }; 36 | 37 | /* Shows error message on UI */ 38 | const showError = (err) => { 39 | document.getElementById('error').style.display = 'block'; 40 | document.getElementById('err-msg').innerText = err; 41 | }; 42 | 43 | /* Converts timestamp into readable local date */ 44 | const formatDate = (date) => { 45 | if (!date) return ''; 46 | return new Date().toLocaleDateString( 47 | "en-US", 48 | { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }, 49 | ); 50 | }; 51 | 52 | /* Using the response from APOD API, update the DOM to render results */ 53 | const updateDom = (apod) => { 54 | document.getElementsByClassName('apod-info')[0].style.display = 'block'; 55 | const titleElem = document.getElementById('apod-title'); 56 | const descriptionElem = document.getElementById('apod-explanation'); 57 | const copyrightElem = document.getElementById('apod-copyright'); 58 | const dateElem = document.getElementById('apod-date'); 59 | const linkElem = document.getElementById('apod-hd-link'); 60 | const iframeElem = document.getElementById('apod-dynamic-content'); 61 | const imageElem = document.getElementById('apod-picture'); 62 | 63 | titleElem.innerText = apod.title; 64 | descriptionElem.innerText = apod.explanation; 65 | copyrightElem.innerText = apod.copyright || ''; 66 | dateElem.innerText = formatDate(apod.date); 67 | linkElem.innerText = 'View HD Image'; 68 | linkElem.setAttribute('href', apod.hdurl || apod.url); 69 | 70 | if (apod.media_type !== 'image') { 71 | iframeElem.setAttribute('src', apod.url); 72 | iframeElem.style.display = 'block'; 73 | imageElem.style.display = 'none'; 74 | linkElem.innerText = 'View Dynamic Content'; 75 | } 76 | 77 | document.getElementById('response').innerHTML = prettyPrint(apod); 78 | } 79 | 80 | /* Updates API docs with endpoint based on hostname */ 81 | const setApiEndPoints = () => { 82 | const { apod, image } = makeEndpointUrls(); 83 | document.getElementById('get-apod').innerText = apod; 84 | document.getElementById('get-img').innerText = image; 85 | } 86 | 87 | /* Format API JSON response in nicely */ 88 | const prettyPrint = (json) => { 89 | if (typeof json != 'string') { json = JSON.stringify(json, undefined, 2); } 90 | json = json.replace(/&/g, '&').replace(//g, '>'); 91 | return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { 92 | let cls = 'number'; 93 | if (/^"/.test(match)) { 94 | cls = (/:$/.test(match))? 'key' : 'string'; 95 | } else if (/true|false/.test(match)) { cls = 'boolean'; } 96 | else if (/null/.test(match)) { cls = 'null'; } 97 | return '' + match + ''; 98 | }); 99 | }; 100 | 101 | /* When page has loaded, make request then update the DOM */ 102 | document.addEventListener('DOMContentLoaded', (e) => { 103 | makeRequest(); 104 | setApiEndPoints(); 105 | }); 106 | -------------------------------------------------------------------------------- /static/styles.css: -------------------------------------------------------------------------------- 1 | :root{--primary:#8120F7;--textColor:#F3F3F3;--bgLighter:#2c2c2d;--bgDarker:#1f1f20;--primaryLight:#B174FB}::selection{color:var(--bgDarker);background:var(--primary)}html{scroll-behavior:smooth}body{margin:0;background:var(--bgDarker);font-family:'Gentium Plus', serif;color:var(--textColor)}main{display:flex;flex-direction:column;justify-content:center;align-items:center;width:fit-content;margin:0 auto}h1,h2,p.loader-text{filter: drop-shadow(2px 2px #1e1e1e);font-family:'Kanit', sans-serif;background:linear-gradient(to bottom right, #534EE1, #A532F4);-webkit-background-clip:text;-webkit-text-fill-color:transparent}a{text-shadow:2px 2px 4px #1a1a1a;color:var(--primaryLight)}h1.main-title{margin:0.5rem auto;font-size:3rem}.api-wrapper,.today-wrapper{background:var(--bgLighter);width:fit-content;max-width:750px;margin:1rem;padding:1rem;border-radius:12px;text-align:center;box-shadow:2px 2px 4px #1a1a1a}.today-wrapper iframe.apod-iframe,.today-wrapper img.apod-picture{width:100%;max-width:500px;border-radius:8px;box-shadow:2px 2px 4px #1a1a1a}.today-wrapper iframe.apod-iframe{display:none;margin:0 auto;min-height:500px;border:none}#error,.apod-info{text-align:left;padding:1rem;margin:1rem auto;max-width:calc(500px - 2rem);border-radius:8px;box-shadow:2px 2px 4px #1a1a1a;background:#1f1f20b3;display:none}.apod-info h2{margin:0;color:var(--primary)}.apod-info p.meta-wrap{margin:0}.apod-info p#apod-explanation{margin:0;font-style:italic}.apod-info span#apod-copyright{margin-left:1rem}.apod-info span#apod-copyright,.apod-info span#apod-date{font-size:0.8rem;opacity:0.5}a#apod-hd-link{background-image:linear-gradient(to right, #4751E6 0%, #844BDD 51%, #423CF4 100%);margin:0.5rem 0;padding:1rem 2rem;text-align:center;transition:0.5s;background-size:200% auto;color:var(--textColor);box-shadow:2px 2px 4px #1a1a1a;border-radius:8px;display:block;width:fit-content;text-decoration:none;font-weight:bold;font-family:'Kanit', sans-serif}a#apod-hd-link:hover{box-shadow:6px 6px 12px #1a1a1a;background-position:right center;color:var(--textColor);text-decoration:none}footer.i-have-feet{text-align:center;background:var(--bgLighter);font-style:italic;opacity:0.8;box-shadow:0 -2px 4px #1a1a1a}.loader-svg{width:100px;margin:1rem auto}#error .err-title{font-family:'Kanit', sans-serif;color:#ff006c;margin:0.2rem}#error #err-msg{font-family:monospace;margin:0.2rem}@media screen and (max-width: 540px){.link-wrapper{flex-direction:column;align-items:center}}@media screen and (max-width: 1256px){.link-wrapper{display:flex;background:var(--bgLighter);box-shadow:2px 2px 4px #1a1a1a;border-radius:12px;max-width:750px;width:calc(100% - 2rem);margin:1rem;justify-content:center}}@media screen and (min-width: 1256px){.link-wrapper{position:absolute;left:0.5rem;top:0.5rem}}.link-wrapper a.link-to{width:14rem;display:block;text-decoration:none;border-radius:12px;border:3px solid var(--primary);margin:0.5rem;padding:0.25rem 0.5rem;transition:all 0.35s;position:relative}.link-wrapper a.link-to:hover{box-shadow:0 0 40px 40px #6009CA inset;border-color:#6009CA}.link-wrapper a.link-to p.link-description,.link-wrapper a.link-to p.link-title{margin:0;color:var(--textColor);text-decoration:none}.link-wrapper .link-sub-wrap{display:flex;justify-content:center;align-items:center}.link-wrapper .link-sub-wrap img.link-icon{width:2rem;margin-right:0.25rem}.link-wrapper a.link-to p.link-title{font-size:1.1rem;font-family:'Kanit', sans-serif;text-shadow:2px 2px 4px #1a1a1a}.link-wrapper a.link-to p.link-description{font-size:0.9rem;font-style:italic}body{background-color:var(--bgDarker);background-image:url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%232c2c2d' fill-opacity='0.4'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E")}.api-wrapper{text-align:left;margin:1rem;width:calc(100% - 4rem);display:grid;grid-template-columns:repeat(2, 1fr)}@media screen and (max-width: 540px){.api-wrapper{display:flex;flex-direction:column}}.api-wrapper h2{grid-column-end:span 2;font-size:2.5rem;margin:0;text-align:center}.api-wrapper h3{font-family:'Kanit', sans-serif}.api-wrapper .request-wrap span.meth{background-image:linear-gradient(to right, #4751E6 0%, #844BDD 91%);padding:0.125rem 0.25rem;border-radius:6px 0 0 6px}.api-wrapper .request-wrap code{padding:0.4rem;background:var(--bgDarker);border-radius:0 6px 6px 0}.api-wrapper img.response-img{width:300px;border-radius:8px;box-shadow:2px 2px 4px #1a1a1a;border:2px solid var(--primary)}.api-wrapper h4.response-heading{margin:1rem 0 0.5rem;font-weight:bold;font-style:italic;font-size:1.1rem}.api-wrapper pre#response{background:var(--bgDarker);border-radius:8px;box-shadow:2px 2px 4px #1a1a1a;overflow:scroll;font-size:0.7rem;max-width:335px}pre .key{color:#B87EFF;font-weight:bold}pre .string{color:#b3f9d8;font-style:italic}pre .number{color:#FAFD9E}pre .boolean{color:#f9a1ad}pre .null{color:#a1d8f9} 2 | -------------------------------------------------------------------------------- /static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Go-APOD 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
42 | 43 | 59 | 60 |
61 |

Astronomy Picture of the Day

62 | Astronomy Picture of the Day 68 | 69 |
70 | 71 |

Loading...

72 |
73 |
74 |

Error Fetching Data from NASA

75 |

Check the console for more info

76 |
77 |
78 |

79 |

80 |

81 | 82 |
83 |
84 | 85 |
86 |

API

87 |
88 |

Raw Image

89 |
90 | GEThttps://go-apod.herokuapp.com/image 91 |
92 |

Response

93 | 94 |
95 |
96 |

Full Info

97 |
98 | GEThttps://go-apod.herokuapp.com/apod 99 |
100 |

Response

101 |

102 |   {
103 |     "copyright":"island universe",
104 |     "date":"2018-12-28",
105 |     "explanation":"Barred spiral galaxy NGC 1365 is truly a majestic island universe some 200,000 light-years...",
106 |     "hdurl":"https://apod.nasa.gov/apod/image/1812/NGC1365_HaLRGBpugh.jpg",
107 |     "media_type":"image",
108 |     "service_version":"v1",
109 |     "title":"NGC 1365: Majestic Island Universe",
110 |     "url":"https://apod.nasa.gov/apod/image/1812/NGC1365_HaLRGBpugh1024.jpg"
111 |   }       
112 | 
113 |
114 | 115 |
116 |
117 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | Alicia Sykes . 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright © 2022 Alicia Sykes 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the “Software”), to deal in 6 | the Software without restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 8 | Software, and to permit persons to whom the Software is furnished to do so, 9 | subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 15 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 16 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 17 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 18 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 19 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | package main 23 | 24 | import ( 25 | "context" 26 | "embed" 27 | _ "embed" 28 | "encoding/json" 29 | "fmt" 30 | "io" 31 | "io/fs" 32 | "log" 33 | "net/http" 34 | "os" 35 | "strings" 36 | "time" 37 | 38 | "github.com/go-chi/chi/v5" 39 | "github.com/go-chi/cors" 40 | "github.com/kelseyhightower/envconfig" 41 | ) 42 | 43 | //go:embed static 44 | var static embed.FS 45 | 46 | func spaHandler(data embed.FS, root string) http.HandlerFunc { 47 | contentStatic, err := fs.Sub(fs.FS(data), root) 48 | if err != nil { 49 | log.Fatalf("failed to create static site content: %v", err) 50 | } 51 | 52 | fs := http.FileServer(http.FS(contentStatic)) 53 | return func(w http.ResponseWriter, r *http.Request) { 54 | if _, err := data.ReadFile(root + r.RequestURI); os.IsNotExist(err) { 55 | http.StripPrefix(r.RequestURI, fs).ServeHTTP(w, r) 56 | } else { 57 | fs.ServeHTTP(w, r) 58 | } 59 | } 60 | } 61 | 62 | type config struct { 63 | Port string `envconfig:"PORT" default:"8080"` 64 | CORSAllowedOrigins string `envconfig:"CORS_ALLOWED_ORIGINS" default:"*"` 65 | NASAAPIKey string `envconfig:"NASA_API_KEY" required:"true"` 66 | NASABaseURL string `envconfig:"NASA_BASE_URL" default:"https://api.nasa.gov/planetary/apod"` 67 | } 68 | 69 | type server struct { 70 | router *chi.Mux 71 | client *http.Client 72 | conf *config 73 | } 74 | 75 | func newServer(conf *config) *server { 76 | return &server{ 77 | router: chi.NewRouter(), 78 | client: &http.Client{Timeout: 60 * time.Second}, 79 | conf: conf, 80 | } 81 | } 82 | 83 | func (s *server) routes() *chi.Mux { 84 | s.router.Use( 85 | cors.New(cors.Options{ 86 | AllowedOrigins: strings.Split(s.conf.CORSAllowedOrigins, ","), 87 | AllowedMethods: []string{http.MethodGet, http.MethodPost, http.MethodOptions, http.MethodPut, http.MethodDelete}, 88 | AllowedHeaders: []string{"Accept", "Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token", "Authorization"}, 89 | }).Handler, 90 | ) 91 | s.router.Get("/image", s.handleImage()) 92 | s.router.Get("/apod", s.handleApod()) 93 | s.router.Get("/*", spaHandler(static, "static")) 94 | return s.router 95 | } 96 | 97 | type apodResponse struct { 98 | Copyright string `json:"copyright,omitempty"` 99 | Date string `json:"date,omitempty"` 100 | Explanation string `json:"explanation,omitempty"` 101 | HdUrl string `json:"hdurl,omitempty"` 102 | MediaType string `json:"media_type,omitempty"` 103 | ServiceVersion string `json:"service_version,omitempty"` 104 | Title string `json:"title,omitempty"` 105 | Url string `json:"url,omitempty"` 106 | } 107 | 108 | // fetch the url of nasa apod 109 | func (s *server) apod(ctx context.Context) (*apodResponse, error) { 110 | url := fmt.Sprintf("%s?api_key=%s", s.conf.NASABaseURL, s.conf.NASAAPIKey) 111 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) 112 | if err != nil { 113 | return nil, err 114 | } 115 | 116 | resp, err := s.client.Do(req) 117 | if err != nil { 118 | return nil, err 119 | } 120 | defer resp.Body.Close() 121 | 122 | result := apodResponse{} 123 | err = json.NewDecoder(resp.Body).Decode(&result) 124 | if err != nil { 125 | return nil, err 126 | } 127 | return &result, nil 128 | } 129 | 130 | func (s *server) handleImage() http.HandlerFunc { 131 | return func(w http.ResponseWriter, r *http.Request) { 132 | apod, err := s.apod(r.Context()) 133 | if err != nil { 134 | log.Printf("apodUrl: %v", err) 135 | http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) 136 | return 137 | } 138 | 139 | req, err := http.NewRequestWithContext(r.Context(), http.MethodGet, apod.Url, nil) 140 | if err != nil { 141 | log.Printf("image: http.NewRequestWithContext: %v", err) 142 | http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) 143 | return 144 | } 145 | 146 | resp, err := s.client.Do(req) 147 | if err != nil { 148 | log.Printf("image: client.Do: %v", err) 149 | http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) 150 | return 151 | } 152 | defer resp.Body.Close() 153 | 154 | w.Header().Set("Content-Length", fmt.Sprint(resp.ContentLength)) 155 | w.Header().Set("Content-Type", resp.Header.Get("Content-Type")) 156 | _, err = io.Copy(w, resp.Body) 157 | if err != nil { 158 | log.Printf("image: io.Copy: %v", err) 159 | http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) 160 | } 161 | } 162 | } 163 | 164 | func (s *server) handleApod() http.HandlerFunc { 165 | return func(w http.ResponseWriter, r *http.Request) { 166 | results, reqErr := s.apod(r.Context()) 167 | if reqErr != nil { 168 | http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) 169 | return 170 | } 171 | w.Header().Set("Content-Type", "application/json") 172 | json.NewEncoder(w).Encode(results) 173 | } 174 | } 175 | 176 | // Start web server 177 | func main() { 178 | var conf config 179 | err := envconfig.Process("apod", &conf) 180 | if err != nil { 181 | log.Fatal(err) 182 | } 183 | 184 | fmt.Println("\033[1;92m🌌 Go-APOD running at http://localhost:" + conf.Port + "/\033[0m") 185 | log.Fatal(http.ListenAndServe(":"+conf.Port, newServer(&conf).routes())) 186 | } 187 | -------------------------------------------------------------------------------- /.github/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Go-APOD

4 | 5 |

6 | A CORS-enabled, no-auth wrapper to NASA's Astronomy Picture of the Day
7 | Public API: apod.as93.net

8 | 9 |

10 | 11 | 12 |
13 | Contents 14 | 15 | - [API Usage](#api-usage) 16 | - [`/apod`](#apod) 17 | - [`/image`](#image) 18 | - [Deployment](#deployment) 19 | - [Heroku](#heroku) 20 | - [Docker](#docker) 21 | - [Executable](#from-executable) 22 | - [From Source](#from-source) 23 | - [Development](#building-locally) 24 | - [Project Commands](#commands) 25 | - [Configuration Options](#environmental-variables) 26 | - [Frontend App](#app) 27 | - [Contributing](#contributing) 28 | - [License](#license) 29 | 30 |
31 | 32 | --- 33 | 34 | ## API Usage 35 | 36 | 37 | ### `/apod` 38 | 39 | > Returns full JSON info about todays picture 40 | 41 | **Example** 42 | 43 | ``` 44 | GET https://go-apod.herokuapp.com/apod 45 | ``` 46 | 47 | **Response** 48 | 49 | ```json 50 | { 51 | "date": "2022-06-20", 52 | "explanation": "There, just right of center, what is that? The surface of Mars keeps revealing new surprises with the recent discovery of finger-like rock spires. The small nearly-vertical rock outcrops were imaged last month by the robotic Curiosity rover on Mars. Although similar in size and shape to small snakes, the leading explanation for their origin is as conglomerations of small minerals left by water flowing through rock crevices. After these relatively dense minerals filled the crevices, they were left behind when the surrounding rock eroded away. Famous rock outcrops on Earth with a similar origin are called hoodoos. NASA's Curiosity Rover continues to search for new signs of ancient water in Gale Crater on Mars, while also providing a geologic background important for future human exploration. Explore Your Universe: Random APOD Generator", 53 | "hdurl": "https://apod.nasa.gov/apod/image/2206/MarsFingers_Curiosity_1338.jpg", 54 | "media_type": "image", 55 | "service_version": "v1", 56 | "title": "Rock Fingers on Mars", 57 | "url": "https://apod.nasa.gov/apod/image/2206/MarsFingers_Curiosity_960.jpg" 58 | } 59 | ``` 60 | 61 | --- 62 | 63 | ### `/image` 64 | 65 | > Returns todays image 66 | 67 | **Example** 68 | 69 | ```html 70 | Astronomy Picture of the Day 75 | ``` 76 | 77 | **Response** 78 | 79 | Astronomy Picture of the Day 80 | 81 | --- 82 | 83 | ## Deployment 84 | 85 | > _Go-APOD can be self-hosted, either with Docker, via the 1-click Vercel or Heroku deployment, or by running the executable directly._
86 | > A NASA API Key is required, which you can sign up for at [api.nasa.gov](https://api.nasa.gov/). 87 | 88 | ### Vercel 89 | 90 | [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FLissy93%2Fgo-apod&env=NASA_API_KEY&envDescription=Your%20NASA%20API%20key.%20It's%20free%2C%20get%20it%20at%20https%3A%2F%2Fapi.nasa.gov&envLink=https%3A%2F%2Fapi.nasa.gov&project-name=apod&repository-name=go-apod&demo-title=Go-APOD&demo-description=A%20demo%20is%20published%20to%20apod.as93.net&demo-url=https%3A%2F%2Fapod.as93.net%2F&demo-image=https%3A%2F%2Fraw.githubusercontent.com%2FLissy93%2Fgo-apod%2Fmaster%2Fstatic%2Fassets%2Fpwa%2Fapple-touch-icon.png) 91 | 92 | ### Heroku 93 | 94 | [![Deploy to Heroku](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/Lissy93/go-apod) 95 | 96 | ### Docker 97 | A multi-arch container is available on DockerHub, under [`lissy93/apod`](https://hub.docker.com/r/lissy93/apod), or GHCR as [`ghcr.io/lissy93/go-apod`](https://github.com/Lissy93/go-apod/pkgs/container/go-apod).
Or, use this [`docker-compose.yml`](https://github.com/Lissy93/go-apod/blob/master/docker-compose.yml) template, and just populate with your API key and run `docker compose up`. 98 | 99 | ```bash 100 | docker run -p 8080:8080 -e NASA_API_KEY='XXX' -d lissy93/apod 101 | ``` 102 | 103 | ### From Executable 104 | 105 | Each release has pre-compiled binaries attached for Windows, Mac and Linux, which can be run directly. 106 | From the [Releases Page](https://github.com/Lissy93/go-apod/releases), download and extract the version for your system, then execute it with: `NASA_API_KEY='XXX' ./go-apod` 107 | 108 | ### From Source 109 | 110 | See the [Building Locally](#building-locally) section below 111 | 112 | --- 113 | 114 | 115 | ## Building Locally 116 | 117 | > If you haven't already done so, you'll need to [install Go Lang](https://go.dev/doc/install).
118 | > Then clone the repo `git clone https://github.com/Lissy93/go-apod.git && cd go-apod` 119 | 120 | 121 | ### Commands 122 | - Run Directly > `go run .` 123 | - Compile App > `go build` 124 | - Run Tests > `go test` 125 | 126 | ### Environmental Variables 127 | 128 | - `NASA_API_KEY` (Required) - Your API Key, you can sign up for one at [api.nasa.gov](https://api.nasa.gov/) 129 | - `PORT` (Optional) - The port to start the web server on, defaults to `8080` 130 | - `CORS_ALLOWED_ORIGINS` (Optional) - List of origins which can use the API, defaults to `*` / all 131 | - `NASA_BASE_URL` (Optional) - The base URL upstream GET requests, defaults to NASA's APOD API 132 | 133 | --- 134 | 135 | ## App 136 | 137 | > The service also includes an optional simple web app, which can be used to show todays image and associated information from the API. 138 | 139 |

140 | 141 | 142 | 143 | 144 |

145 | 146 | --- 147 | 148 | ## Contributing 149 | 150 | Contributions of any kind are very welcome, and would be much appreciated :) 151 | For Code of Conduct, see [Contributor Convent](https://www.contributor-covenant.org/version/2/1/code_of_conduct/). 152 | 153 | To get started, fork the repo, make your changes, add, commit and push the code, then come back here to open a pull request. If you're new to GitHub or open source, [this guide](https://www.freecodecamp.org/news/how-to-make-your-first-pull-request-on-github-3#let-s-make-our-first-pull-request-) or the [git docs](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) may help you get started, but feel free to reach out if you need any support. 154 | 155 | [![contributors](https://contrib.rocks/image?repo=lissy93/go-apod)](https://github.com/Lissy93/go-apod/graphs/contributors) 156 | 157 | --- 158 | 159 | ## License 160 | 161 | > _**[Lissy93/Go-APOD](https://github.com/Lissy93/go-apod)** is licensed under [MIT](https://github.com/Lissy93/go-apod/blob/master/LICENSE) © [Alicia Sykes](https://aliciasykes.com) 2022._
162 | > For information, see TLDR Legal > MIT 163 | 164 |
165 | Expand License 166 | 167 | ``` 168 | The MIT License (MIT) 169 | Copyright (c) Alicia Sykes 170 | 171 | Permission is hereby granted, free of charge, to any person obtaining a copy 172 | of this software and associated documentation files (the "Software"), to deal 173 | in the Software without restriction, including without limitation the rights 174 | to use, copy, modify, merge, publish, distribute, sub-license, and/or sell 175 | copies of the Software, and to permit persons to whom the Software is furnished 176 | to do so, subject to the following conditions: 177 | 178 | The above copyright notice and this permission notice shall be included install 179 | copies or substantial portions of the Software. 180 | 181 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 182 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANT ABILITY, FITNESS FOR A 183 | PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 184 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 185 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 186 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 187 | ``` 188 | 189 |
190 | 191 | --- 192 | 193 | 194 |

195 | © Alicia Sykes 2022
196 | Licensed under MIT
197 |
198 | Thanks for visiting :) 199 |

200 | 201 | 202 | 214 | 215 | --------------------------------------------------------------------------------