You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: function.go
    path of file: ./repos/event-gateway/libkv
    
    the code of the file until where you have to start completion: package libkv

import (
	"bytes"
	"encoding/json"
	"regexp"

	validator "gopkg.in/go-playground/validator.v9"

	"go.uber.org/zap"

	"github.com/serverless/event-gateway/function"
	"github.com/serverless/event-gateway/metadata"
	"github.com/serverless/libkv/store"
)

// FunctionKey is a key under which function data is stored KV store.
type FunctionKey struct {
	Space string
	ID    function.ID
}

func (key FunctionKey) String() string {
	return key.Space + "/" + string(key.I
    
func (service Service) UpdateFunction(fn *function.Function) (*function.Function, error) {
	if err := validateFunction(fn); err != nil {
		return nil, err
	}

	_, err := service.FunctionStore.Get(FunctionKey{Space: fn.Space, ID: fn.ID}.String(), &store.ReadOptions{Consistent: true})
	if err != nil {
		return nil, &function.ErrFunctionNotFound{ID: fn.ID}
	}

	byt, err := json.Marshal(fn)
	if err != nil {
		return nil, &function.ErrFunctionValidation{Message: err.Error()}
	}

	err = service.FunctionStore.Put(FunctionKey{Space: fn.Space, ID: fn.ID}.String(), byt, nil)
	if err != nil {
		return nil, err
	}

	service.Log.Debug("Function updated.", zap.Object("function", fn))

	return fn, nil
}