swagger_handler

package
v3.11.29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Handler = func(dst map[string]interface{}, fsys fs.FS) http.HandlerFunc {
	c := yamlcodec.NewCodec()
	return func(w http.ResponseWriter, r *http.Request) {
		if r.Method != http.MethodGet {
			w.WriteHeader(http.StatusNotFound)
			return
		}

		path := r.URL.Path
		if len(path) > 1 && path[0] == '/' {
			path = path[1:]
		}

		buf, err := fs.ReadFile(fsys, path)
		if err != nil {
			w.WriteHeader(http.StatusInternalServerError)
			_, _ = w.Write([]byte(err.Error()))
			return
		}

		if dst == nil {
			w.WriteHeader(http.StatusOK)
			_, _ = w.Write(buf)
			return
		}

		var src interface{}

		if err = c.Unmarshal(buf, src); err != nil {
			w.WriteHeader(http.StatusInternalServerError)
			_, _ = w.Write([]byte(err.Error()))
			return
		}

		if err = rutil.Merge(src, dst); err != nil {
			w.WriteHeader(http.StatusInternalServerError)
			_, _ = w.Write([]byte(err.Error()))
			return
		}

		if buf, err = c.Marshal(src); err != nil {
			w.WriteHeader(http.StatusInternalServerError)
			_, _ = w.Write([]byte(err.Error()))
			return
		}

		w.WriteHeader(http.StatusOK)
		_, _ = w.Write(buf)
	}
}

Handler append to generated swagger data from dst map[string]interface{}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL