mirror of
				https://github.com/SourceFellows/gobuch.git
				synced 2025-11-04 15:46:17 +01:00 
			
		
		
		
	initial import
This commit is contained in:
		
							
								
								
									
										5
									
								
								microservices/rfc7808/client/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								microservices/rfc7808/client/go.mod
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
module golang.source-fellows.com/samples/rfc7808/server
 | 
			
		||||
 | 
			
		||||
go 1.13
 | 
			
		||||
 | 
			
		||||
require github.com/moogar0880/problems v0.1.1
 | 
			
		||||
							
								
								
									
										2
									
								
								microservices/rfc7808/client/go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								microservices/rfc7808/client/go.sum
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
github.com/moogar0880/problems v0.1.1 h1:bktLhq8NDG/czU2ZziYNigBFksx13RaYe5AVdNmHDT4=
 | 
			
		||||
github.com/moogar0880/problems v0.1.1/go.mod h1:5Dxrk2sD7BfBAgnOzQ1yaTiuCYdGPUh49L8Vhfky62c=
 | 
			
		||||
							
								
								
									
										26
									
								
								microservices/rfc7808/client/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								microservices/rfc7808/client/main.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net/http"
 | 
			
		||||
 | 
			
		||||
	"github.com/moogar0880/problems"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	res, err := http.Get("http://localhost:8080/a")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Fatal("could not request")
 | 
			
		||||
	}
 | 
			
		||||
	defer res.Body.Close()
 | 
			
		||||
	if res.StatusCode != http.StatusOK {
 | 
			
		||||
		problem := &problems.DefaultProblem{}
 | 
			
		||||
		bites, _ := ioutil.ReadAll(res.Body)
 | 
			
		||||
		json.Unmarshal(bites, problem)
 | 
			
		||||
		log.Println(problem.ProblemTitle())
 | 
			
		||||
	} else {
 | 
			
		||||
		log.Println("ok")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										5
									
								
								microservices/rfc7808/server/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								microservices/rfc7808/server/go.mod
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
module golang.source-fellows.com/samples/rfc7808/server
 | 
			
		||||
 | 
			
		||||
go 1.13
 | 
			
		||||
 | 
			
		||||
require github.com/moogar0880/problems v0.1.1 // indirect
 | 
			
		||||
							
								
								
									
										2
									
								
								microservices/rfc7808/server/go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								microservices/rfc7808/server/go.sum
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
github.com/moogar0880/problems v0.1.1 h1:bktLhq8NDG/czU2ZziYNigBFksx13RaYe5AVdNmHDT4=
 | 
			
		||||
github.com/moogar0880/problems v0.1.1/go.mod h1:5Dxrk2sD7BfBAgnOzQ1yaTiuCYdGPUh49L8Vhfky62c=
 | 
			
		||||
							
								
								
									
										22
									
								
								microservices/rfc7808/server/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								microservices/rfc7808/server/main.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"net/http"
 | 
			
		||||
 | 
			
		||||
	"github.com/moogar0880/problems"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func handleHttp(res http.ResponseWriter, req *http.Request) {
 | 
			
		||||
	NotFound := problems.NewStatusProblem(http.StatusNotFound)
 | 
			
		||||
	bites, _ := json.Marshal(NotFound)
 | 
			
		||||
	res.WriteHeader(http.StatusNotFound)
 | 
			
		||||
	res.Header().Add("Content-Type", "application/json")
 | 
			
		||||
	res.Write(bites)
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	http.HandleFunc("/a/", handleHttp)
 | 
			
		||||
	http.ListenAndServe(":8080", nil)
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user