middlewares

package
v0.0.0-...-f0ca03d Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

Middlewares

(data_format.go) Pluggable Interface for Handling Multiple Input/Output Formats

This repository demonstrates the implementation of a pluggable interface in an API to support multiple input/output formats, including JSON, XML, and YAML. The interface allows users to interact with the API using their preferred data format while maintaining a common data structure internally.

Overview

Modern APIs often need to cater to a variety of data formats to accommodate different client needs. This project addresses this challenge by providing a flexible system for processing requests and responses in different formats, while still adhering to a uniform data structure within the application.

Features

  • Supports JSON, XML, and YAML input and output formats.
  • Utilizes a middleware for format detection, conversion, and content negotiation.
  • Maintains a common data structure that acts as an intermediary between different formats.
  • Provides flexibility for users to specify their preferred input/output format.

Examples

  • JSON Input:

    { "name": "John Doe", "age": 30, "email": "john@example.com" }
    
  • XML Input:

    <user>
      <name>John Doe</name>
      <age>30</age>
      <email>john@example.com</email>
    </user>
    
  • YAML Input:

    name: John Doe
    age: 30
    email: john@example.com
    

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatMiddleware

func FormatMiddleware() gin.HandlerFunc

func JwtAuthMiddleware

func JwtAuthMiddleware() gin.HandlerFunc

Types

type CommonDataStructure

type CommonDataStructure struct {
	ID       int    `json:"patientId" xml:"patientId" yaml:"patientId" binding:"required"`
	Name     string `json:"fullName" xml:"fullName" yaml:"fullName" binding:"required"`
	Age      int    `json:"age" xml:"age" yaml:"age"`
	Address  string `json:"address" xml:"address" yaml:"address"`
	Email    string `json:"email" xml:"email" yaml:"email" binding:"required"`
	Password string `json:"password" xml:"password" yaml:"password" binding:"required"`
	Role     string `json:"role" xml:"role" yaml:"role" binding:"required"`
}

Jump to

Keyboard shortcuts

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