Skip to content

Commit

Permalink
Merge pull request #5 from yazilimcimekani/rewrite/golang
Browse files Browse the repository at this point in the history
Golang Rewrite
  • Loading branch information
mertssmnoglu authored Dec 3, 2023
2 parents 759e5e6 + ccbfa23 commit 3be549d
Show file tree
Hide file tree
Showing 20 changed files with 255 additions and 1,021 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Continuous Integration
run-name: CI

on:
push:
branches:
- main
- ci
pull_request:
branches:
- main
workflow_dispatch:

jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '>=1.21.4'
- name: Setup Staticcheck
uses: dominikh/[email protected]
with:
version: "2023.1.6"
install-go: false
min-go-version: "1.21.4"
146 changes: 21 additions & 125 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,130 +1,26 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Environment variables
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/
production.env
prod.env

# DynamoDB Local files
.dynamodb/
# Test binary, built with `go test -c`
*.test

# TernJS port file
.tern-port
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# Dependency directories (remove the comment below to include it)
# vendor/

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# Go workspace file
go.work
21 changes: 0 additions & 21 deletions .prettierignore

This file was deleted.

9 changes: 0 additions & 9 deletions .prettierrc.json

This file was deleted.

39 changes: 0 additions & 39 deletions app.ts

This file was deleted.

5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/yazilimcimekani/mdoctor-server

go 1.21.4

require github.com/joho/godotenv v1.5.1
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
7 changes: 0 additions & 7 deletions index.ts

This file was deleted.

22 changes: 8 additions & 14 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
set shell := ["powershell.exe", "-c"]

readme:
@just -l

install:
@yarn
tidy:
@go mod tidy

build: install
if (Test-Path -Path dist) { rmdir dist }
@yarn tsc
@mkdir dist/public
@cp -r public/* dist/public
run:
@go run main.go

dev:
@start http://localhost:3000
@yarn dev
build:
@go build main.go

start:
@yarn start
clean:
if [ -e main ]; then rm main; fi
29 changes: 29 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"fmt"
"log"
"net/http"

"github.com/joho/godotenv"
"github.com/yazilimcimekani/mdoctor-server/pkg/controllers"
"github.com/yazilimcimekani/mdoctor-server/pkg/env"
)

func main() {
// Load the .env file
envErr := godotenv.Load()
if envErr != nil {
log.Fatal("Error loading .env file")
}
port := env.GetEnv("PORT", "8080")

// Define the handlers
http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir("public"))))
http.HandleFunc("/markdown", controllers.Markdown())

// Start the server on given port
startMessage := fmt.Sprintf("Server started on http://localhost:%s", port)
log.Println(startMessage)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
}
32 changes: 0 additions & 32 deletions package.json

This file was deleted.

18 changes: 18 additions & 0 deletions pkg/controllers/markdown.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package controllers

import (
"fmt"
"net/http"

"github.com/yazilimcimekani/mdoctor-server/pkg/mdtohtml"
)

func Markdown() func(w http.ResponseWriter, r *http.Request) {
const mdTemplatePath = "views/md.html"
var html string = mdtohtml.LoadFile(mdTemplatePath)
fullHTML := fmt.Sprintf(html, mdtohtml.MarkdownToHtml("# Hello World\nSa\n# Hello\n###### Hellooooooooo i am a h6\nAnd i'm a normal text\n"))

return func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(fullHTML))
}
}
10 changes: 10 additions & 0 deletions pkg/env/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package env

import "os"

func GetEnv(key string, defaultValue string) string {
if os.Getenv(key) == "" {
return defaultValue
}
return os.Getenv(key)
}
Loading

0 comments on commit 3be549d

Please sign in to comment.