Bläddra i källkod

initial workable go project

master
sp 4 år sedan
förälder
incheckning
04fb03b875
5 ändrade filer med 88 tillägg och 3 borttagningar
  1. +1
    -0
      .idea/SFM_Loan_RestApi.iml
  2. +29
    -0
      config.go
  3. +5
    -0
      config.json
  4. +14
    -0
      go.mod
  5. +39
    -3
      main.go

+ 1
- 0
.idea/SFM_Loan_RestApi.iml Visa fil

@@ -2,6 +2,7 @@
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$USER_HOME$/GolandProjects/SFM-loan" />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />

+ 29
- 0
config.go Visa fil

@@ -0,0 +1,29 @@
package main

import (
"encoding/json"
log "github.com/sirupsen/logrus"
"io/ioutil"
)

type configuration struct {
Host string
Port string
DocRoot string
}

var configFile = "config.json"
var config = configuration{}

func (m *configuration) readConfig() (e error) {
log.Printf("read Path config from %s\r\n", configFile)
body, e := ioutil.ReadFile(configFile)
if e != nil {
log.Fatal("Cannot read config from " + configFile)
return
}
e = json.Unmarshal(body, m)

//TODO: check config before proceed further
return
}

+ 5
- 0
config.json Visa fil

@@ -0,0 +1,5 @@
{
"Host":"127.0.0.1",
"Port":"8080",
"DocRoot": "./html/"
}

+ 14
- 0
go.mod Visa fil

@@ -0,0 +1,14 @@
module SFM_Loan_RestApi

go 1.15

replace biukop.com/sfm/loan => /home/sp/GolandProjects/SFM-loan

require (
biukop.com/sfm/loan v0.0.0-00010101000000-000000000000
github.com/VividCortex/mysqlerr v0.0.0-20201215173831-4c396ae82aac
github.com/brianvoe/gofakeit/v6 v6.0.1
github.com/go-sql-driver/mysql v1.5.0
github.com/sirupsen/logrus v1.7.0
github.com/stretchr/testify v1.2.2
)

+ 39
- 3
main.go Visa fil

@@ -1,6 +1,7 @@
package main

import (
"biukop.com/sfm/loan"
"fmt"
"log"
"net/http"
@@ -8,11 +9,46 @@ import (

func main() {

err := config.readConfig() //wechat API config
if err != nil {
log.Println(err)
log.Fatalf("unable to read %s, program quit\n", configFile)
return
}

setupRootFileServer()
//always the last one
setupHTTPHandler()

}

func setupRootFileServer() {

}

func setupHTTPHandler() {
http.HandleFunc("/api", HelloHandler)
http.HandleFunc("/upload", HelloHandler)
http.HandleFunc("/crmfiles/", HelloHandler)
http.HandleFunc("/dumprequest", HelloHandler)
http.HandleFunc("/MP_verify_6JqVkftKr39GMakA.txt", HelloHandler)
http.HandleFunc("/spa/redirect", HelloHandler)
http.HandleFunc("/iapi/getAccessToken", HelloHandler)
http.HandleFunc("/iapi/createWechatQr", HelloHandler)
http.HandleFunc("/crmpixel.png", HelloHandler) //tracking pixel.
http.HandleFunc("/crmcache", HelloHandler)
http.HandleFunc("/spa/editprofile", HelloHandler)
http.HandleFunc("/spa/livecast", HelloHandler)
http.HandleFunc("/spa/editmeeting", HelloHandler)

http.HandleFunc("/", HelloHandler)
fmt.Println("Server started at port 8080")
log.Fatal(http.ListenAndServe(":8080", nil))
fmt.Printf("Server started at port %s\n", config.Port)
log.Fatal(http.ListenAndServe(config.Host+":"+config.Port, nil))

}

func HelloHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, there\n")
p := loan.People{}
p.FakeNew()
fmt.Fprintf(w, "Hello, there %s, %+v\n", loan.Version, p)
}

Laddar…
Avbryt
Spara