github.com/prebid/prebid-server/v2@v2.18.0/endpoints/getuids.go (about)

     1  package endpoints
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/julienschmidt/httprouter"
     7  	"github.com/prebid/prebid-server/v2/config"
     8  	"github.com/prebid/prebid-server/v2/usersync"
     9  
    10  	"encoding/json"
    11  )
    12  
    13  type userSyncs struct {
    14  	BuyerUIDs map[string]string `json:"buyeruids,omitempty"`
    15  }
    16  
    17  // NewGetUIDsEndpoint implements the /getuid endpoint which
    18  // returns all the existing syncs for the user
    19  func NewGetUIDsEndpoint(cfg config.HostCookie) httprouter.Handle {
    20  	return httprouter.Handle(func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
    21  		cookie := usersync.ReadCookie(r, usersync.Base64Decoder{}, &cfg)
    22  		usersync.SyncHostCookie(r, cookie, &cfg)
    23  
    24  		userSyncs := new(userSyncs)
    25  		userSyncs.BuyerUIDs = cookie.GetUIDs()
    26  		json.NewEncoder(w).Encode(userSyncs)
    27  	})
    28  }