版本号
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Jiaowu.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/system")]
|
||||
public sealed class SystemController : ControllerBase
|
||||
{
|
||||
[AllowAnonymous]
|
||||
[HttpGet("version")]
|
||||
[ProducesResponseType<SystemVersionResponse>(StatusCodes.Status200OK)]
|
||||
public SystemVersionResponse GetVersion()
|
||||
{
|
||||
var assembly = typeof(SystemController).Assembly;
|
||||
var informationalVersion = assembly
|
||||
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
|
||||
.InformationalVersion;
|
||||
var version = informationalVersion?.Split('+', 2)[0]
|
||||
?? assembly.GetName().Version?.ToString(3)
|
||||
?? "unknown";
|
||||
|
||||
return new SystemVersionResponse(version);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record SystemVersionResponse(string Version);
|
||||
Reference in New Issue
Block a user