Fixed headers and added endpoints
This commit is contained in:
		| @ -66,8 +66,8 @@ func (g group) Endpoint(path string, f apiFunc) *group { | |||||||
| } | } | ||||||
|  |  | ||||||
| func StatusAndContent(w http.ResponseWriter, status int, contentType string) { | func StatusAndContent(w http.ResponseWriter, status int, contentType string) { | ||||||
| 	w.WriteHeader(status) |  | ||||||
| 	w.Header().Add("Content-Type", contentType) | 	w.Header().Add("Content-Type", contentType) | ||||||
|  | 	w.WriteHeader(status) | ||||||
| } | } | ||||||
|  |  | ||||||
| func WriteJSON(w http.ResponseWriter, status int, v any) error { | func WriteJSON(w http.ResponseWriter, status int, v any) error { | ||||||
|  | |||||||
							
								
								
									
										17
									
								
								webapi.go
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								webapi.go
									
									
									
									
									
								
							| @ -9,7 +9,10 @@ import ( | |||||||
|  |  | ||||||
| func InitServer(host string) server.Api { | func InitServer(host string) server.Api { | ||||||
| 	app := server.NewApi(host) | 	app := server.NewApi(host) | ||||||
| 	app.Group("/api").Endpoint("gen", ImageHandler) | 	app.Group("/api"). | ||||||
|  | 		Endpoint("gen", ImageHandler). | ||||||
|  | 		Endpoint("hello", HelloHandler) | ||||||
|  | 	app.Group("/").Endpoint("", HealthHandler) | ||||||
| 	return app | 	return app | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -26,3 +29,15 @@ func ImageHandler(w http.ResponseWriter, r *http.Request) error { | |||||||
| 	} | 	} | ||||||
| 	return server.WriteBlob(w, 200, "image/png", *img) | 	return server.WriteBlob(w, 200, "image/png", *img) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | type hello struct { | ||||||
|  | 	Hello string | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func HelloHandler(w http.ResponseWriter, r *http.Request) error { | ||||||
|  | 	return server.WriteJSON(w, 200, hello{"world"}) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func HealthHandler(w http.ResponseWriter, r *http.Request) error { | ||||||
|  | 	return server.WritePlain(w, 200, "ok") | ||||||
|  | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user