go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/web/accepted_provider.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package web
     9  
    10  // AcceptedProvider returns a result provider by the Accept
    11  // header value on the incoming request.
    12  func AcceptedProvider(ctx Context) ResultProvider {
    13  	contentType, _ := NegotiateContentType(ctx.Request(),
    14  		"application/json",
    15  		"application/gob",
    16  		"text/html",
    17  		"text/plain",
    18  	)
    19  
    20  	switch contentType {
    21  	case "application/json":
    22  		return JSONResultProvider{}
    23  	case ContentTypeApplicationGob:
    24  		return GobResultProvider{}
    25  	case "text/html":
    26  		return ctx.Views()
    27  	case "text/plain":
    28  		return TextResultProvider{}
    29  	default:
    30  		return JSONResultProvider{}
    31  	}
    32  }